接口调试,HttpWebRequest和HttpWebResponse使用…

2018-06-17 22:43:40来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

public void queryIdCardSelects
{
string url=“jiekoudizhi.html”;
string param="jiekoucanshu";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";

            byte[] data = Encoding.UTF8.GetBytes(param);
            request.ContentLength = data.Length;
            using (Stream reqStream = request.GetRequestStream())
            {
                reqStream.Write(data, 0, data.Length);
                reqStream.Close();
            }

            string result = "";
            HttpWebResponse resp = (HttpWebResponse)request.GetResponse();
            Stream stream = resp.GetResponseStream();
            //获取响应内容  
            using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
            {
                result = reader.ReadToEnd();
            }
}

  

接口回调数据处理

            TextReader read = new StreamReader(Request.InputStream, Encoding.UTF8);
            string READSTR = read.ReadToEnd();

            READSTR = HttpUtility.UrlDecode(READSTR, Encoding.GetEncoding("utf-8"));
            log.Info(READSTR);

  

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:C#基础---浅谈XML读取以及简单的ORM实现

下一篇:初步学习XML的基本代码