zoukankan      html  css  js  c++  java
  • .net post提交

    接口调用:post提交获取返回值

    String SUPPLIER_ADD_REQ = "Request=";//键
    String SUPPLIER_REQ_URL = https://xxxxxxx/query";//方法链接
    String createDesXML = "sjfslfajfsafsjj";//值
    String result = null;

    //获取接口返回结果
    result =SendPost(SUPPLIER_ADD_REQ + createDesXML, SUPPLIER_REQ_URL);

    public static string SendPost(string formData, string formUrl)
    {
    try
    {

    //注意提交的编码 这边是需要改变的 这边默认的是Default:系统当前编码

    byte[] postData = Encoding.UTF8.GetBytes(formData);

    // 设置提交的相关参数
    HttpWebRequest request = WebRequest.Create(formUrl) as HttpWebRequest;
    Encoding myEncoding = Encoding.UTF8;
    request.Method = "POST";
    request.KeepAlive = false;
    request.AllowAutoRedirect = true;
    request.ContentType = "application/x-www-form-urlencoded";
    request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
    request.ContentLength = postData.Length;

    // 提交请求数据
    System.IO.Stream outputStream = request.GetRequestStream();
    outputStream.Write(postData, 0, postData.Length);
    outputStream.Close();

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
    string result = reader.ReadToEnd();
    reader.Close();
    return result;
    }
    catch (Exception ex)
    {
    return "error";
    }
    }

    总结:这是我post提交接口返回数据的方法

  • 相关阅读:
    C语言实现mq收发数据的函数
    4G通信模块在ARM平台下的应用
    4G 通信模块在ARM 平台下的应用
    修改web前端访问端口
    从零开始用 Flask 搭建一个网站(一)
    Python实现Windows定时关机
    前端和后端的数据交互(jquery ajax+python flask+mysql)
    python开源项目及示例代码
    Django读取Mysql数据并显示在前端
    C++关于string的一些用法
  • 原文地址:https://www.cnblogs.com/zttb/p/9210447.html
Copyright © 2011-2022 走看看