为什么我的post老是报500的错误呢,求指导~~
------解决思路----------------------
楼主,对照如下代码看看:
///<summary>
///httpPOST请求url---json
///</summary>
///<paramname="url"></param>
///<paramname="postData">json数据</param>
///<returns></returns>
publicstaticstringGetHttpPostRequest_json(stringurl,stringpostData)
{
stringstrURL=url;
System.Net.HttpWebRequestrequest;
request=(System.Net.HttpWebRequest)WebRequest.Create(strURL);
request.Method="POST";
request.ContentType="application/json;charset=UTF-8";//传递的参数类型
stringparaUrlCoded=postData;
byte[]payload;
payload=System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
request.ContentLength=payload.Length;
Streamwriter=request.GetRequestStream();
writer.Write(payload,0,payload.Length);
writer.Close();
System.Net.HttpWebResponseresponse;
response=(System.Net.HttpWebResponse)request.GetResponse();
System.IO.Streams;
s=response.GetResponseStream();
stringStrDate="";
stringstrValue="";
StreamReaderReader=newStreamReader(s,Encoding.UTF8);
while((StrDate=Reader.ReadLine())!=null)
{
strValue+=StrDate+"rn";
}
returnstrValue;
}