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提交接口返回数据的方法

  • 相关阅读:
    免费部署Woocall到您自己的网站上
    服务器控件开发之复杂属性
    删除数据库的所有存储过程、主键、外键、索引等
    怎样在dropdownlist的每一项前加一个或多个空格
    Java的内部类学习
    StringUtils全览 (转)
    Java异常大全
    Java web 开发小问题总结(持续更新中)
    Java常用方法总结(持续更新中)
    Python 常用函数
  • 原文地址:https://www.cnblogs.com/zttb/p/9210447.html
Copyright © 2011-2022 走看看