现在在做一个需求,要求用HTTP post方式调用接口实现数据上传,需求内容如下:协议:http方式:POST POST字符串参数为code={0}&keys={1}&writedoc={2}
{0},{1},{2}分别对应参数code,keys,writedoc的值。 代码如下:
string PostData = string.Format("code={0}&keys={1}&writedoc={2}", "10001", "d587fc05fe8c47b7", xmldoc);
Uri url = new Uri(surl);
WebRequest myHttpWebRequest = WebRequest.Create(url);
myHttpWebRequest.Method = "POST";
myHttpWebRequest.Timeout = 3000;
UTF8Encoding encoding = new UTF8Encoding();
byte[] byte1 = encoding.GetBytes(PostData);
//myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
myHttpWebRequest.ContentLength = byte1.Length;
//发送成功后接收返回的XML信息
using (Stream newStream = myHttpWebRequest.GetRequestStream())
{
newStream.Write(byte1, 0, byte1.Length);
HttpWebResponse response = (HttpWebResponse)myHttpWebRequest.GetResponse();
string lcHtml = string.Empty;
Encoding enc = Encoding.GetEncoding("UTF-8");
using(Stream stream = response.GetResponseStream())
{
StreamReader streamReader = new StreamReader(stream, enc);
lcHtml = streamReader.ReadToEnd();
return lcHtml;
}
}
可是在响应完成之后,服务器那边接收不到我窜过去的参数,各位大神看看我哪里写的不对