为什么Wikipedia返回带有特定URL的301响应代码? [英] Why Wikipedia returns 301 response code with certain URL?
问题描述
一些带有法国口音的特殊请求。
var client = new HttpClient();
var data0 =等待客户端。GetAsync( http://fr.wikipedia.org/wiki/Monastère_d’Arkadi);
这个简单的代码产生:
状态码:301,ReasonPhrase:永久移动,版本:1.1
有什么想法吗?实际上,下载纽约的法语文章是可行的。我什至尝试对名称进行编码,但无济于事。
维基百科发送HTTP 301,指示
由于浏览器自动使用新的位置,因此可以成功在浏览器中下载页面。
更新
如果我输入
https://fr.wikipedia.org/wiki/Monast%C3%A8re_d% 27Arkadi
(301响应的Location标头中的值)在IE中,我得到了HTTP200。但是,我也获得了使用HttpClient的HTTP 301。
如果我使用
WebClient
,则会收到错误尝试重定向的次数过多。似乎这里发生了某种重定向循环。我正在进一步探索。
更新2
我下载了该页面使用wget ,带有详细的日志记录。请注意,wget无法验证Wikipedia的SSL证书,并且存在两种重定向:从http URL到https URL,然后再到带有转义字符的URL。
E:\软件\GnuWin32\bin> wget -v --no-check-certificatehttp://fr.wikipedia.org/wiki/Monastère_d'Arkadi
SYSTEM_WGETRC = c:/ progra〜1 / wget / etc / wgetrc
syswgetrc = E:\软件\GnuWin32 / etc / wgetrc
--2015-10-17 23:22: 43-- http://fr.wikipedia.org/wiki/Monast%E8re_d'Arkadi
解决fr.wikipedia.org ... 208.80.154.224
连接到fr.wikipedia.org | 208.80。 154.224 |:80 ...已连接。
HTTP请求已发送,正在等待响应... 301 TLS重定向
位置:https://fr.wikipedia.org/wiki/Monast%E8re_d'Arkadi [以下]
--2015- 10-17 23:22:44-- https://fr.wikipedia.org/wiki/Monast%E8re_d'Arkadi
正在连接至fr.wikipedia.org | 208.80.154.224 |:443 ...已连接。
警告:无法验证fr.wikipedia.org的证书,由`/ C = BE / O = GlobalSign nv-sa / CN = GlobalSign组织Va颁发
附加证件CA-SHA256-G2':
无法在本地验证发行人的权限。
HTTP请求已发送,正在等待响应... 301永久移动了
位置:https://fr.wikipedia.org/wiki/Monast%C3%A8re_d%27Arkadi [以下]
- 2015-10-17 23:22:44-- https://fr.wikipedia.org/wiki/Monast%C3%A8re_d%27Arkadi
连接到fr.wikipedia.org | 208.80.154.224 |:443。 .. 连接的。
警告:无法验证由/ C = BE / O = GlobalSign nv-sa / CN = GlobalSign组织Va发行的fr.wikipedia.org证书CA-SHA256-G2':
无法在本地验证发行人的权限。
HTTP请求已发送,正在等待响应... 200 OK
长度:未指定[text / html]
保存到:`MonastA re_d'Arkadi'
[ < =>]在0.4秒内为171,252 463K / s
2015-10-17 23:22:45(463 KB / s)-`MonastA re_d'Arkadi'保存了[171252]
Some requests with special character in this with the french accents.
var client = new HttpClient(); var data0 = await client.GetAsync("http://fr.wikipedia.org/wiki/Monastère_d'Arkadi");
This simple code yields:
StatusCode: 301, ReasonPhrase: 'Moved Permanently', Version: 1.1
Any ideas what is happening? Downloading the French article of New York works in fact. I´ve even try to encode the the name but nothing works.
解决方案Wikipedia sends an HTTP 301 indicating that the permanent home of
is now
If you look at the response header, you will see that the Location header has the updated URL.
It succeeds in downloading the page in a browser because the browser automatically uses the new Location.
UPDATE
If I enter
https://fr.wikipedia.org/wiki/Monast%C3%A8re_d%27Arkadi
(the value in the Location header of the 301 response) in IE, I get an HTTP 200. However, I also get an HTTP 301 using HttpClient.If I use
WebClient
, I get the error "Too many redirections were attempted." It looks like there is some sort of redirect loop happening here. I'm exploring this further.UPDATE 2
I downloaded the page using wget, with verbose logging. Note that wget was unable to validate the SSL certificate for Wikipedia, and that there were two redirects: From the http URL to the https URL, then again to the URL with escaped characters.
E:\Software\GnuWin32\bin>wget -v --no-check-certificate http://fr.wikipedia.org/wiki/Monastère_d'Arkadi SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc syswgetrc = E:\Software\GnuWin32/etc/wgetrc --2015-10-17 23:22:43-- http://fr.wikipedia.org/wiki/Monast%E8re_d'Arkadi Resolving fr.wikipedia.org... 208.80.154.224 Connecting to fr.wikipedia.org|208.80.154.224|:80... connected. HTTP request sent, awaiting response... 301 TLS Redirect Location: https://fr.wikipedia.org/wiki/Monast%E8re_d'Arkadi [following] --2015-10-17 23:22:44-- https://fr.wikipedia.org/wiki/Monast%E8re_d'Arkadi Connecting to fr.wikipedia.org|208.80.154.224|:443... connected. WARNING: cannot verify fr.wikipedia.org's certificate, issued by `/C=BE/O=GlobalSign nv-sa/CN=GlobalSign Organization Va lidation CA - SHA256 - G2': Unable to locally verify the issuer's authority. HTTP request sent, awaiting response... 301 Moved Permanently Location: https://fr.wikipedia.org/wiki/Monast%C3%A8re_d%27Arkadi [following] --2015-10-17 23:22:44-- https://fr.wikipedia.org/wiki/Monast%C3%A8re_d%27Arkadi Connecting to fr.wikipedia.org|208.80.154.224|:443... connected. WARNING: cannot verify fr.wikipedia.org's certificate, issued by `/C=BE/O=GlobalSign nv-sa/CN=GlobalSign Organization Va lidation CA - SHA256 - G2': Unable to locally verify the issuer's authority. HTTP request sent, awaiting response... 200 OK Length: unspecified [text/html] Saving to: `MonastA"re_d'Arkadi' [ <=> ] 171,252 463K/s in 0.4s 2015-10-17 23:22:45 (463 KB/s) - `MonastA"re_d'Arkadi' saved [171252]
这篇关于为什么Wikipedia返回带有特定URL的301响应代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!