码迷,mamicode.com
首页 > Web开发 > 详细

pplication/x-www-form-urlencoded 请求格式调用

时间:2019-06-14 14:24:35      阅读:558      评论:0      收藏:0      [点我收藏+]

标签:array   toe   exception   urlencode   res   sage   requests   ret   try   

public string Post(string Url, string jsonParas)
{
string res = string.Empty;
            try
            {
byte[] byteArray = Encoding.Default.GetBytes(jsonParas);
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(Url));
                webReq.Method = "POST";
                webReq.ContentType = "application/x-www-form-urlencoded";

                webReq.ContentLength = byteArray.Length;
                Stream newStream = webReq.GetRequestStream();
                newStream.Write(byteArray, 0, byteArray.Length);
                newStream.Close();
                HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
                StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
res = sr.ReadToEnd();
                sr.Close();
                response.Close();
                newStream.Close();
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
return res;

}

//调用
string para = "method=AZTSSchedule&projectNo=04118180&stationIds=12331232&productId=ASZXSS";
Post("http://xxxx:8888/product/project", para);

pplication/x-www-form-urlencoded 请求格式调用

标签:array   toe   exception   urlencode   res   sage   requests   ret   try   

原文地址:https://www.cnblogs.com/wdnrsjd/p/11022824.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!