【发布时间】:2016-04-30 08:51:33
【问题描述】:
我已经集成了一个选项,供用户通过 PayPal 在我正在创建的网上商店中进行在线购物。当我开始收到此错误时,问题突然出现:
You must write ContentLength bytes to the request stream before calling [Begin]GetResponse.
Http调用的代码如下:
public string HttpCall(string NvpRequest)
{
string url = pEndPointURL;
string strPost = NvpRequest + "&" + buildCredentialsNVPString();
strPost = strPost + "&BUTTONSOURCE=" + HttpUtility.UrlEncode(BNCode);
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
objRequest.Timeout = Timeout;
objRequest.Method = "POST";
objRequest.ContentLength = strPost.Length;
try
{
using (StreamWriter myWriter = new StreamWriter(objRequest.GetRequestStream()))
{
myWriter.Write(strPost.ToString());
}
}
catch (Exception e)
{
}
//Retrieve the Response returned from the NVP API call to PayPal.
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse(); // this is the line where the exception occurs...
string result;
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
result = sr.ReadToEnd();
}
return result;
}
有人可以帮我解决这个问题吗?一天前它工作得很好,现在它给了我这个错误?
【问题讨论】:
标签: c# asp.net paypal httpwebrequest httpwebresponse