Click here to Skip to main content
12,629,804 members (27,761 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET PayPal
Using beautiful article "[^]"

I have created sandbox accounts, sandbox seller, ipn_pal.htm, set the ipn url to match, gone to the ipn test site, every time I get HTTP Error 405 Method Not Allowed.

I went back to the original paypal code and removed all the good stuff... same error.

Paypal says it's the host that has the problem. The host has never seen the problem before. I have tried it on another site (different host), same problem.

Please tell me what I've done wrong! Thanks!!!!

I have it stripped down to this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<%@ Page Language="C#"    %>
<%@ Import Namespace = "System" %>
<%@ Import Namespace = "System.IO" %>
<%@ Import Namespace = "System.Text" %>
<%@ Import Namespace = "System.Net" %>
<%@ Import Namespace = "System.Web" %>
<script type="text/javascript" Language="JavaScript">
//Some JavaScript you may need goes here
<script Language="C#" Option="Explicit" type="text/C#"  runat="server">
protected void Page_Load(object sender, EventArgs e)
//Post back to either sandbox or live
string strSandbox = "";
string strLive = "";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);
//Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
string strRequest = Encoding.ASCII.GetString(param);
strRequest += "&cmd=_notify-validate";
req.ContentLength = strRequest.Length;
//for proxy
//WebProxy proxy = new WebProxy(new Uri("http://url:port#"));
//req.Proxy = proxy;
//Send the request to PayPal and get the response
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
if (strResponse == "VERIFIED")
//check the payment_status is Completed
//check that txn_id has not been previously processed
//check that receiver_email is your Primary PayPal email
//check that payment_amount/payment_currency are correct
//process payment
else if (strResponse == "INVALID")
//log for manual investigation
//log response/ipn data for manual investigation
  // --- end of page load --
<head runat="server" >
<title>IPN PayPal</title>
<body runat="server">
<label id="debuggy" runat="server"/>
<h2> my test page</h2>
Load this first to check the syntax of your page
Posted 7-Oct-10 5:54am
Nathan Staudt 7-Oct-10 11:07am
Is there a reason you're specifically using ASCII instead of Unicode? If the request to your page has any unicode characters, that might be messing things up :)
Metrakay 7-Oct-10 11:58am
Not really, I just did a copy/paste. Both the link above and Paypal's sample code had it.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

This code works fine for me.

405 errors often arise with the POST method, however not all ISPs allow the POST method necessary to process the request.
All 405 errors can be traced to configuration of the Web server and security governing access to the content of the Web site, so should easily be explained by your ISP.

As the code you have posted is the same as outlined here[^] on the paypal site I would have a talk with the hosts and get them to investigate, other than that you may want to look into if you need to use a proxy and uncomment the proxy section of the code, replacing the "url:port#" part with the correct proxy information (if you need to use a proxy that is).
Metrakay 7-Oct-10 11:58am
That's what I thought, I was just hoping I was wrong and that I had done something stupid...

I had tried both sets of code to try to eliminate any errors on my end.

Thank you for your help!

I have forwarded this information to the host.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.161205.3 | Last Updated 7 Oct 2010
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100