我已经为用户集成了一个选项,通过PayPal在我正在创建的网上商店进行在线购物.当我开始收到此错误时突然出现问题:
You must write ContentLength bytes to the request stream before calling [Begin]GetResponse.
Run Code Online (Sandbox Code Playgroud)
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 …Run Code Online (Sandbox Code Playgroud)