我已經集成了一個選項供用戶通過PayPal在我正在創建的網上商店上進行網上購物。問題就來了時,突然我開始收到此錯誤:PayPal API的問題HTTP呼叫
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;
}
有人能幫助我嗎?它在一天前運行良好,現在它給了我這個錯誤?
真的嗎?沒人知道? :/ – perkes456