zoukankan      html  css  js  c++  java
  • .net后台调用API接口

    string dd = model.Fatherid;
    string serviceAddress = "http://public.data.test.cn/api/PropertyData/GetFloorBuilding";
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceAddress);

    request.Method = "POST";
    request.ContentType = "application/json";
     string strContent = @"{ ""Fatherid"": " + "'" + dd + "'" + "}";//参数
    using (StreamWriter dataStream = new StreamWriter(request.GetRequestStream()))
    {
    dataStream.Write(strContent);//写入参数
    dataStream.Close();
    }
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    string encoding = response.ContentEncoding;
    if (encoding == null || encoding.Length < 1)
    {
    encoding = "UTF-8"; //默认编码
    }
    StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(encoding));
    string retString = reader.ReadToEnd();
    //JObject jo = JObject.Parse(retString);
    //解析josn
    GetFloorBuildingResult jo1 = JsonConvert.DeserializeObject<GetFloorBuildingResult>(retString);
    return jo1;

    //GetFloorBuildingResult  返回结果

  • 相关阅读:
    Java入门
    Java入门
    Java入门
    Java入门
    Java入门
    Java入门
    Java入门
    random库的使用
    程序的控制结构
    数据类型
  • 原文地址:https://www.cnblogs.com/tfeblog/p/10619301.html
Copyright © 2011-2022 走看看