HttpWebRequest causes 400 bad request when AllowAutoRedirect is true

T

TK

I'm using HttpWebRequest (with HEAD) to check for broken links on
certain websites. I'm receiving several 400 bad request responses.

With a network sniffer i can see that the initial response is a 301
(moved permanently). Then HttpWebRequest tries another request using
the url given in the response (since request.AllowAutoRedirect=true by
default). This second request causes the 400 (bad request) response
because the url is not encoded before the request is sent.

I encode the url explicitly before making the initial request but the
second request happens behind the scenes. Is there a way to avoid this
error, by somehow encoding the url of a request generated due to a
redirection?

Has anyone else encountered this problem, any suggestions, solutions?
Thanks,
TK
 

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