开发者

Why does a link with "@" work in my browser but C# HttpWebRequest gives 404 (The remote server returned an error: (405) Method Not Allowed.)

开发者 https://www.devze.com 2022-12-19 23:35 出处:网络
Anyone have an idea offhand regarding why a link with an \"@\" in it works on my browser, but when I go to get this particular link in my HttpWebRequest code I get a 405 error?

Anyone have an idea offhand regarding why a link with an "@" in it works on my browser, but when I go to get this particular link in my HttpWebRequest code I get a 405 error?

The remote server returned an error: (405) Method Not Allowed.

The example link in question:

http://internal_link/@api/deki/site/lo开发者_开发问答go.png

thanks


The @ sign is a reserved character in a URL.

reserved    = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
              "$" | ","

(See http://www.ietf.org/rfc/rfc2396.txt)

So I'd suggest to escape (something the browser does automatically), using %40 instead of @.


An http is an http request. The server doesn't care whether it's from a browser or something else. If it rejects one and not the other, it's because you're not sending the same request. Some things to check might be the user agent, cookies, or whether the browser is somehow altering the @ sign in that url before sending it. You can use a program like fiddler to check the request sent by the browser and alter your code to make sure it sends the same request.

0

精彩评论

暂无评论...
验证码 换一张
取 消