C#POST数据到服务器<非.NET语言>问题,接收为空问题
代码如下
string strReturn = "";
string url = @"http://aa.XXX.com/bb.do";
try
{
byte[] obtPostData = Encoding.UTF8.GetBytes(sbJSON.ToString());
HttpWebRequest orqRequest = (HttpWebRequest)WebRequest.Create(url);
orqRequest.Timeout = 3000;
orqRequest.Method = "POST";
orqRequest.ContentType = "application/json;charset=utf-8";
orqRequest.ContentLength = obtPostData.Length;
Stream stream;
using (stream = orqRequest.GetRequestStream())
{
stream.Write(obtPostData, 0, obtPostData.Length);
}
HttpWebResponse orsResponse = (HttpWebResponse)orqRequest.GetResponse();
using (Stream responseStream = orsResponse.GetResponseStream())
{
using (StreamReader streamRead = new StreamReader(responseStream, Encoding.UTF8))
{
strReturn = streamRead.ReadToEnd();
}
}
}
catch (WebException e)
{
//写日志
LogManager.WriteLog(LogFile.Trace, e.Message.ToString());
}