我无法从 url 中检索图像。以前,在设置 HttpClient 标头之前,我根本无法连接到该站点。我可以从其他来源检索图像,但不能从这个特定来源检索图像。
检索图像的代码:
var img = new BitmapImage();
img.BeginInit();
img.UriSource = new Uri("https://i1.adis.ws/i/jpl/jd_083285_a?qlt=80&w=600&h=425&v=1&fmt=webp", UriKind.RelativeOrAbsolute);
img.EndInit();
Console.Out.WriteLine();
ImageShoe.Source = img;
Run Code Online (Sandbox Code Playgroud)
如果我尝试使用不同的 url 检索不同的图像,例如https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png它工作正常。
更新:
似乎使用字节数组是可行的方法,但我仍然不确定这里有什么问题。
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
var url = "https://i1.adis.ws/i/jpl/jd_083285_a?qlt=80&w=600&h=425&v=1&fmt=webp";//baseUrl + productUrl;
var result = await client.GetByteArrayAsync(new Uri(
MemoryStream buf = new MemoryStream(result);
var image = new BitmapImage();
image.StreamSource = buf;
this.ImageShoe.Source = image;
Run Code Online (Sandbox Code Playgroud)