Redirected request in HttpWebRequest does not maintain specified method!!

J

Jon Davis

This appears to be a critical bug in the .NET Framework. Surely I am wrong
though! PLEASE HELP if anyone has any idea?

Thanks,
Jon

________________________________

From: Jon Davis [mailto:[email protected]]
Sent: Friday, March 26, 2004 9:31 PM
To: (e-mail address removed)
Subject: RE: [bloggerDev] Blogger API still not working for me :`(


Seems the AutoRedirect feature in the HttpWebRequest object in .NET
Framework does not maintain the specified method. It's changing from a POST
to a GET.

Sniffed conversation is as follows.

----------------------------
REQUEST (api.blogger.com:80)
----------------------------
POST /api HTTP/1.1
Content-Type: text/xml
User-Agent: Accentra.XmlRpc 1.4
Content-Length: 495
Expect: 100-continue
Connection: Keep-Alive
Host: api.blogger.com

--------
RESPONSE
--------
HTTP/1.0 302 Found
Date: Sat, 27 Mar 2004 05:25:31 GMT
Server: Apache
Location: http://www.blogger.com/api
Connection: close
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>302 Found</TITLE>
</HEAD><BODY>
<H1>Found</H1>
The document has moved <A HREF="http://www.blogger.com/api">here</A>.<P>
</BODY></HTML>

----------------------------
REQUEST (www.blogger.com:80)
----------------------------

GET /api HTTP/1.1
Content-Type: text/xml
User-Agent: Accentra.XmlRpc 1.4
Connection: Keep-Alive
Host: www.blogger.com

--------
RESPONSE
--------

HTTP/1.0 302
Date: Sat, 27 Mar 2004 05:25:31 GMT
Server: Apache
Vary: Accept-Encoding
Location: http://www.blogger.com/developers/api/
Content-Length: 0
Connection: close
Content-Type: text/html

-------
REQUEST
-------

GET /developers/api/ HTTP/1.1
Content-Type: text/xml
User-Agent: Accentra.XmlRpc 1.4
Connection: Keep-Alive
Host: www.blogger.com

--------
RESPONSE
--------

HTTP/1.0 200
Date: Sat, 27 Mar 2004 05:25:33 GMT
Server: Apache
Vary: Accept-Encoding
Set-Cookie: JSESSIONID=B3B178D78922757B3761FDC6EB1C454F; Path=/
Set-Cookie: ServerID=1290; Path=/
Set-Cookie: PyraID2=; Expires=Thu, 01-Jan-1970 00:00:10 GMT
Content-Length: 319
Connection: close
Content-Type: text/html;charset=ISO-8859-1

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Blogger API</title>
</head>

<body style="font-family:sans-serif;font-size:12px;">
<h1>Blogger API</h1>
<br><br>
<div >
&nbsp;&nbsp;&nbsp;<a href="1_docs">Blogger API 1.0 Documentation</a>
</div>



</body>
</html>

-----Original Message-----
From: Steve Jenson [mailto:[email protected]]
Sent: Friday, March 26, 2004 10:40 AM
To: (e-mail address removed)
Subject: Re: [bloggerDev] Blogger API still not working for me :`(


Since XML-RPC only uses POST, I redirect to that address when somebody sends
a GET (i.e. they request http://www.blogger.com/api in their browser). It
shouldn't be redirecting otherwise. I see in your code that you've specified
POST as your HTTP method so I can't explain why you're seeing this
particular redirects I did just use the blogger api from Ecto, though, to
post to a test blog of mine.

I would use tcpmon[1] to watch the http traffic to see what's up.

Best,
Steve

[1]: http://www.intertwingly.net/blog/1575.html

Verified. It is redirecting to http://www.blogger.com/developers/api/.
Why?


From: Jon Davis [mailto:[email protected]]
Sent: Friday, March 26, 2004 3:05 AM
To: (e-mail address removed)
Subject: RE: [bloggerDev] Blogger API still not working for me :`(

The code is written in C#.

Why is Blogger redirecting to
http://www.blogger.com/developers/api/ or
HTML thereof, rather than taking the POST?

By the way, this was working before a few months ago, before
redirections occurred.

Jon


From: Jon Davis [mailto:[email protected]]
Sent: Friday, March 26, 2004 12:52 AM
To: (e-mail address removed)
Subject: [bloggerDev] Blogger API still not working for me :`(

Eh, I have finally gotten around to focusing again on Blogger API
support in PowerBlog v2. This is the last round of bug fixes I'm
focusing on in this product before gold release, everything else is
pretty much done.

There are two serious problems I'm having with the Blogger server. I'd
thought it was a redirection problem, with .NET framework not
redirecting its HttpWebRequest properly, but that's apparently not it.
Actually, there are two problems.

The first problem is that the server is terminating the connection
before I've finished sending the request (and yes, as far as I know,
the ContentLength is correct). The second problem is that the crap it
spits back is just the HTML hyperlink to the documentation.
It's not letting me submit the XML-RPC invocation at all!

If you have an HTML-capable newsreader, my comments to this group is
in bold



// calling http://api.blogger.com/api, "blogger.getPost",
...



public object Call(Uri uri, string Method, params object[]
Params) {

// build and send request

HttpWebRequest req =

(HttpWebRequest)WebRequest.Create(uri);

req.Proxy = ProxySettings;

req.CookieContainer = Cookies;

for (int i=0;i<Certificates.Count;i++) {

req.ClientCertificates.Add(Certificates);

}

req.ContentType = "text/xml";

req.Method = "POST";

req.UserAgent = UserAgent;

for (int i=0;i<Headers.Count;i++) {

req.Headers.Add(Headers);

}

string reqBody = BuildRequest(Method, Params,
Encoding);

// so now reqBody is as follows:

// <?xml version="1.0"?>
// <methodCall>
// <methodName>blogger.newPost</methodName>
// <params>
//
<param><value><string>B9C296C4DC1F09ED61129B1FDBFFE589482E5DAA</
string></value></param>
//
<param><value><string>3603466</string></value></param>
//
<param><value><string>[name]</string></value></param>
//
<param><value><string>[pw]</string></value></param>
// <param><value><string>hello, it
works</string></value></param>
//
<param><value><boolean>1</boolean></value></param>
// </params></methodCall>

System.Text.UTF8Encoding encoding =
new UTF8Encoding();

byte[] byteReqBody=encoding.GetBytes(reqBody);

req.ContentLength = byteReqBody.Length;

Stream st;

WebResponse wr;

StreamReader sr;

try {

st = req.GetRequestStream();

} catch (Exception ex) {

throw new XmlRpcConnectException(ex.Message,
ex);

}

try {

st.Write(byteReqBody, 0, byteReqBody.Length);

st.Flush();

} catch (System.Net.WebException ex) {


// dies here, tells me it closed unexpectedly


// ... so here I'm just going to ignore it and
move on

if (ex.Message.IndexOf("closed unexpectedly")
== -1) {

throw ex;

}

}

// receive and parse response

wr = req.GetResponse();

sr = new StreamReader(wr.GetResponseStream());

string resp = sr.ReadToEnd();


// here I find that the response is just some HTML

try { sr.Close();} catch {}

try {wr.Close();} catch {}

try {st.Close();} catch {}


return
XmlRpcTools.ConvertElement(ParseResponse(resp), false);



}
 
J

Joerg Jooss

Jon said:
This appears to be a critical bug in the .NET Framework. Surely I am
wrong though! PLEASE HELP if anyone has any idea?

Thanks,
Jon

________________________________

From: Jon Davis [mailto:[email protected]]
Sent: Friday, March 26, 2004 9:31 PM
To: (e-mail address removed)
Subject: RE: [bloggerDev] Blogger API still not working for me :`(


Seems the AutoRedirect feature in the HttpWebRequest object in .NET
Framework does not maintain the specified method. It's changing from
a POST to a GET.

Have a look at http://ppewww.ph.gla.ac.uk/~flavell/www/post-redirect.html
While (according to the HTTP spec) it's wrong to blindly switch from POST to
GET on a 302, it is the de facto behaviour for practically all web clients
out there :-(

The server-side code should send 307 instead.

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top