2 yong771 yong771 于 2016.03.04 14:58 提问

.NET 3.5 发送POST请求 没反应?

旧项目是运行在3.5环境下 现在业务需要发送post 请求 ,但是代码调试运行到
if (method.ToLower() == "post")
{
HttpWebRequest req = null;
HttpWebResponse rsp = null;
System.IO.Stream reqStream = null;
try
{
req = (HttpWebRequest)WebRequest.Create(url);
req.Method = method;
req.KeepAlive = false;
req.ProtocolVersion = HttpVersion.Version10;
req.Timeout = 5000;
req.ContentType = "application/x-www-form-urlencoded;charset=utf-8";
byte[] postData = Encoding.UTF8.GetBytes(BuildQuery(parameters, "dd"));
//byte[] postData = System.Text.Encoding.Default.GetBytes( BuildQuery(parameters, "dd"));
reqStream = req.GetRequestStream();
reqStream.Write(postData, 0, postData.Length);
rsp = (HttpWebResponse)req.GetResponse();
Encoding encoding = Encoding.GetEncoding(rsp.CharacterSet);
return GetResponseAsString(rsp, encoding);
}
catch (Exception ex)
{
return ex.Message;
}
finally
{
if (reqStream != null) reqStream.Close();
if (rsp != null) rsp.Close();
}
}

  rsp = (HttpWebResponse)req.GetResponse();到这就没反应了也不报错。
        在在4.5环境下测试没问题。

1个回答

caozhy
caozhy   Ds   Rxr 2016.03.06 08:23

这种问题建议用fiddler自己调试下。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!