我正在尝试执行这样的HTTP Post请求:
public string DirectLinkPostResponse(string url, string parameters)
{
var request = WebRequest.Create(url);
var data = Encoding.UTF8.GetBytes(parameters);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())//here's where the error is raised
{
stream.Write(data, 0, data.Length);
}
var response = request.GetResponse();
if (response.GetResponseStream() == null)
return null;
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
return responseString;
}
不幸的是,我收到以下错误消息:
连接尝试失败,因为连接方没有 在一段时间后正确回应,或建立连接 失败,因为已连接的主机无法响应XXX.XX.XX.XX:443
问题是,当我将用户重定向到url(带参数)时,页面会很好地显示,并带有XML结果。有什么我想念的吗?