• ASP.NET后台调用API 方法 POST方式


    /// <summary>
    /// 调用API POST请求与获取结果
    /// </summary>

    ///URL 与 JSON串
    public static string HttpPost(string Url, string postDataStr)
    {
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
    request.Method = "POST";
    request.ContentType = "application/json";
    //request.ContentLength = postDataStr.Length;
    StreamWriter writer = new StreamWriter(request.GetRequestStream(), Encoding.UTF8);
    writer.Write(postDataStr);
    writer.Flush();
    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();

    return retString;
    }

  • 相关阅读:
    Windows系统的DOS常用命令
    常用pom
    ssm整合
    pom依赖集合
    json
    软件项目管理笔记-软件项目计划
    CSS
    网络配置
    用户组
    用户管理
  • 原文地址:https://www.cnblogs.com/LiHeQ/p/7872196.html
Copyright © 2020-2023  润新知