2
私は2つのURL:https://pcr.apple.com/id868222886
とhttps://jigsaw.w3.org/HTTP/300/302.html
を持っています。両方ともロケーションリンクと302レスポンスコードを持っています。HttpClient 302リダイレクト
using System;
using System.IO;
using System.Net.Http;
namespace XaveScor.PodcastFeed
{
public class RemoteFeedSource: FeedSource
{
private string url;
protected virtual HttpMessageHandler Handler => new HttpClientHandler() { AllowAutoRedirect = true };
public override Stream Stream => client.Value.GetStreamAsync(url).Result;
private readonly Lazy<HttpClient> client;
public RemoteFeedSource(string url)
{
client = new Lazy<HttpClient>(() => new HttpClient(Handler), false);
this.url = url;
}
}
}
[TestMethod]
public void Test1() //fail
{
var source = new RemoteFeedSource("https://pcr.apple.com/id868222886");
Assert.AreNotEqual(source.Stream.GetString(), "");
}
[TestMethod]
public void Test2() //success
{
var source = new RemoteFeedSource("https://jigsaw.w3.org/HTTP/300/302.html");
Assert.AreNotEqual(source.Stream.GetString(), "");
}
なぜですか?違いは何ですか?あなたが応答でヘッダを見れば
違いは、どのような意味ですか? 302 =見つかった(そしてリダイレクトによく使われる)、301 =永久に移動された。 [ここ](https://developer.att.com/application-resource-optimizer/docs/best-practices/http-300-status-codes)を参照してください。 – john
@john私は2つの同一のリンクを持っています。しかし、このリンクではHttpClientの作業が異なります。私の質問はなぜですか?なぜ行動が違うのですか? – XaveScor