zoukankan      html  css  js  c++  java
  • WebAPI获取POST参数

    接口代码:

    [HttpPost]

    public void PostTest()

    {

      string content = Request.Content.ReadAsStringAsync().Result;

    }

    请求代码:

    /// <param name="address">接口地址</param>
    /// <param name="data">Json格式字符串参数</param>

    public static string SendRequestPost(string address, string data)

    {

    WebRequest request = null;
    WebResponse response = null;
    Stream requestStream = null;
    StreamReader responseStream = null;
    string responseString = null;
    string method = "POST";
    string contentType = "application/json";
    byte[] bytes = Encoding.UTF8.GetBytes(data);

    request = WebRequest.Create(address);
    request.ContentType = contentType;
    request.Method = method;
    request.Timeout = 300000;
    request.ContentLength = bytes.Length;

    requestStream = request.GetRequestStream();
    requestStream.Write(bytes, 0, bytes.Length);
    requestStream.Close();

    response = request.GetResponse();
    responseStream = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
    responseString = responseStream.ReadToEnd();
    response.Close();

    return responseString;

    }

  • 相关阅读:
    架构设计
    第七章
    第六章
    第五章
    第四章
    第三章
    第二章
    第一章
    链表中环
    实现链表中的部分翻转
  • 原文地址:https://www.cnblogs.com/JosephBee/p/12359516.html
Copyright © 2011-2022 走看看