question

CoreyFleig-6304 avatar image
0 Votes"
CoreyFleig-6304 asked YijingSun-MSFT edited

I get an error message calling the WebResponse Class

I apologize for asking a question about a 7 year old application, but Microsoft wrote it, and I thought it would be bug-free. Ha!

In their example of a webstore, they offer the following code:

     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;
    
         //Retrieve the Response returned from the NVP API call to PayPal.
         HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();

But on the last line (just above), there's an error that I know nothing about:

 System.Net.ProtocolViolationException: 'You must provide a request body if you set ContentLength>0 or SendChunked==true.  Do this by calling [Begin]GetRequestStream before [Begin]GetResponse.'
    
 This exception was originally thrown at this call stack:
     System.Net.HttpWebRequest.GetResponse()
     PayPal_Test.NVPAPICaller.HttpCall(string) in PayPalFunctions.cs
     PayPal_Test.NVPAPICaller.ShortcutExpressCheckout(string, ref string, ref string) in PayPalFunctions.cs
     PayPal_Test.Default.Page_Load(object, System.EventArgs) in Default.aspx.cs
     System.Web.Util.CalliEventHandlerDelegateProxy.Callback(object, System.EventArgs)
     System.Web.UI.Control.OnLoad(System.EventArgs)
     System.Web.UI.Control.LoadRecursive()
     System.Web.UI.Page.ProcessRequestMain(bool, bool)
    
 Do you know if there's anything I can do about this?



not-supported
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @CoreyFleig-6304 ,

System.Net.ProtocolViolationException: 'You must provide a request body if you set ContentLength>0 or SendChunked==true. Do this by calling [Begin]GetRequestStream before [Begin]GetResponse.'

According to your problems,I'm guessing that you have GetRequestStream? Have you tried closing the stream? Your probelm is that you must close the stream before the GetResponse.
Could you post your sample to us? It will help us to solve your problems.
Best regards,
Yijing Sun

0 Votes 0 ·

Your comment about using getrequeststream was perfect - thank you so much.
I got it to run, but now I have to deal with the next failure.

(This example is not working well at all.

This whole exercise is to try posting to my PayPal sandbox business account. I included the userid, password, and signature for the API call, but now it's
saying I don't have permissions to make the API call.

I got the API credentials directly from developer.paypal.com.

What in the world?
Its Error 10002. I know it's PayPal's general purpose authentication error. I'm just frustrated because I used the API credentials they gave me.

Argh!

0 Votes 0 ·

Hi @CoreyFleig-6304 ,
In general the error 10002 can only arise for one of the following reasons:

  1. wrong API credentials, check that you are using the LIVE credentials for the LIVE environment and SANDBOX for the test environment. Also verify that the API credentials have been copied and pasted correctly without any space before or after the value.

  2. your cart/eCommerce is set to the wrong environment: check in your integration if it is set on LIVE or SANDBOX

  3. wrong endpoint of your API calls, this would be in the code of your plugin.

Best regards,
Yijing Sun

0 Votes 0 ·
CoreyFleig-6304 avatar image
0 Votes"
CoreyFleig-6304 answered

Thanks for your help with this. I copy/pasted the API credentials, so they are correct.
As far as the cart/eCommerce, I will check that, but I don't really know enough to
understand exactly what I'm looking for.
THis is an example that MS wrote for sandbox testing, so I assume it's all set up for testing in sandbox.
And they supplied the urls, so I wouldn't know if the endpoints are correct or not, since they supplied it!

I'll take some time and learn all I can, though!

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

YijingSun-MSFT avatar image
0 Votes"
YijingSun-MSFT answered YijingSun-MSFT commented

Hi @CoreyFleig-6304 ,
10002 error usually happens when permissions are set incorrectly in your PayPal account. To allow a third party to make API calls on your behalf, you must explicitly grant them permission to do so. If you've already done this but you got error code 10002, your shopping cart configuration may be the cause. Your vendor needs to know the primary email address on the PayPal account for which they're making the third-party API call. They must add this email address to the API script making the API call on your behalf.

If you're making third-party API calls but not using a vendor and you still get this error, it can be because of the following reasons:

  • Incorrect API information - Follow this procedure to request API Signature or API Certificate credentials.

  • Passing a value in the Subject field - This field should be blank if you're not making an API call on behalf of another person.

One of several different error messages accompanies error code 10002. You're most likely to see this message:
10002: Authentication/Authorization - Username/Password incorrect

This error occurs when you provide an incorrect API username and API password to the PayPal server, for example, if you:

  • Provide the username and password for your actual PayPal account, instead of your API username and API password. PayPal generates your API username and API password when you generate your API Certificate and Signature.

  • Use the same API information for the Sandbox and Live environments. You need to generate separate API information for your Sandbox and Live accounts.

  • Don't update the endpoint to point to PayPal's Live API servers.

  • Format your API Certificate as .txt instead of .pem.

  • Add trailing or leading whitespace on any of the characters.


Best regards,
Yijing Sun


If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for all your comments - this may take some time. I'm consulting all the literature supplied by Microsoft,
and so far all my code matches their code, with the addition of the API information.

For the API call, the account name (business test email address), pwd, and signature are all listed inside the API Credentials dialog box on the developer.paypal.com page.

I'll do what I can to go through it all again and again, and maybe if I'm still getting nowhere, I'll ask for support.

Again, thank you for your advise and insight!


0 Votes 0 ·

Hi @CoreyFleig-6304 ,
You also could ask for help in the PayPal community.
Best regards,
Yijing Sun

0 Votes 0 ·