发起post请求

  

string postUrl = "https://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo";
//string requestStr= Utils.DCUtils.HttpPost(postUrl,HttpUtility.UrlEncode(requestXml));
//string requestStr = Utils.DCUtils.HttpPost(postUrl,"xml="+requestXml);

#region 发起post请求
HttpWebRequest webrequest = (HttpWebRequest)HttpWebRequest.Create(postUrl);
//webrequest.ClientCertificates.Add(cer);
webrequest.Method = "post";

byte[] postdatabyte = Encoding.UTF8.GetBytes(requestXml);
webrequest.ContentLength = postdatabyte.Length;
Stream stream;
stream = webrequest.GetRequestStream();
stream.Write(postdatabyte, 0, postdatabyte.Length);
stream.Close();

HttpWebResponse httpWebResponse = (HttpWebResponse)webrequest.GetResponse();
StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream());
string requestStr = streamReader.ReadToEnd();
#endregion

posted @ 2015-11-20 13:53  jamess  阅读(229)  评论(0编辑  收藏  举报