carviaso / google-checkout-dotnet-sample-code

Automatically exported from code.google.com/p/google-checkout-dotnet-sample-code
0 stars 0 forks source link

Can't read error responses #3

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Send a <charge-order> request to Google for an order that has already
been charged.

What is the expected output? What do you see instead?
Google will return a status code 400, together with an error message. The
calling code will not be able to read the error message because the 400
causes an exception.

Original issue reported on code.google.com by moman...@colspace.com on 14 Sep 2006 at 5:29

GoogleCodeExporter commented 9 years ago

Original comment by martin.o...@gmail.com on 20 Sep 2006 at 11:23

GoogleCodeExporter commented 9 years ago

Original comment by martin.o...@gmail.com on 20 Sep 2006 at 11:23

GoogleCodeExporter commented 9 years ago
Ali emailed:

Martin, 
I found the solution. After the following line throws an exception for 
"400 invalid request", 
HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse(); 

read the data in the catch block like this: 

catch (WebException WebExcp) 
{ 
        if(WebExcp.Response!=null) 
        { 

                HttpWebResponse HttpWResponse = (HttpWebResponse)WebExcp.Response; 
                                        StreamReader sr = new 
StreamReader(HttpWResponse.GetResponseStream(), encode); 

                                        //Convert the stream to a string 
                                        string errorXML = sr.ReadToEnd(); 
                                        sr.Close(); 

} 

/Ali 

Original comment by moman...@google.com on 28 Oct 2006 at 12:20

GoogleCodeExporter commented 9 years ago

Original comment by martin.o...@gmail.com on 9 Dec 2006 at 10:24