NVPAPICaller class throws error

ashwinin
New Community Member

Hello Guys,

Firstly when I integrate NVPAPICaller class for sandbox payment it works fine.But from last few days it is not working, It shows following error

You must write ContentLength bytes to the request stream before calling [Begin]GetResponse.

 

When I debug it NVPAPICaller  class contains one method HttpCall() and it returns error .

At the time of read content

HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
            using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
            {
                result = sr.ReadToEnd();
            }

 

And at the time of write into stream

using (StreamWriter writer = new StreamWriter(objRequest.GetRequestStream()))
                {
                    writer.Write(strPost);
                }

from last few days it's not working.

 

Login to Me Too
3 REPLIES 3

Sun4Tzu
Contributor
Contributor

Hi All,

 

I'm having exactly the same problem as ashwinin and am pretty sure we're not the only developers having this issue. In my case the code was working fine, I handed the site over to the client for review while making no changes to it while that was happening and while it worked for them during their initial tests it suddenly just stopped. So, without any changes to the code that could have caused it, I think we're left with a couple of options. Either there was an update to our hosting environments that caused the problem or something changed with PayPal's sandbox. We'd both greatly appreciate some guidance.

 

Thanks. 

Login to Me Too

PayPal_david
Moderator
Moderator

Hi guys.

 

Thanks for reaching out to us in regards to this. Sorry to hear that you have been experiencing difficulties on your accounts recently.

 

I would advise you to reach out to our Technical Support team directly so that they can assist you further with the difficulties that you have been experiencing on your accounts recently.

 

There are some different ways that you can reach out to our Technical Support Team. Firstly, if you have a Twitter account, you can reach them through the Twitter handle @PayPal_MTS or alternatively, you can contact them directly through the Technical Support website here https://www.paypal-techsupport.com/

 

Please let us know how it goes.
David.

Login to Me Too

Sun4Tzu
Contributor
Contributor

Apparently there was a security change with PayPal (or so I read in another forum). As such, it was advised to add the following (change is bold text) to the paypalfunctions.cs file. This is for ASP.NET 4.0. I read that 4.5 is different. This is the only change I made and once again I'm able to process payments.

 

try
        {
            ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
            using (StreamWriter myWriter = new StreamWriter(objRequest.GetRequestStream()))
            {                
                myWriter.Write(strPost);
            }
        }
Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.