图片网址正确无误,但在.net core 2.0应用中通过httpClient请求给出了空响应

时间:2019-07-01 06:47:11

标签: c# .net-core

我有一个.net core 2.0控制台应用程序,我正在其中下载图像

private static HttpClient Client = new HttpClient();
public static async Task<MemoryStream> GetImageData(string filename)
{
    try
    {
        var data = await Client.GetAsync(filename);
        byte[] imageStream = await data.Content.ReadAsByteArrayAsync();
        return new MemoryStream(imageStream);
    }
    catch (Exception ex)
    {
        throw;
    }
}

....
// Some logic
using (MemoryStream imageStream = await ImageUtilities.GetImageData(item))
{
    if (index1 >= 0 && index1 < 2)
    {
        using (var resized = ImageUtilities.ResizeImageWithSameAspectRation(imageStream, 262, 230))
        {
            if (resized != null)
            {
                PropertyRefNo = PropertyRefNo.Replace("#", "-");
                string fileName = PropertyRefNo + "_" + index1 + ".jpeg";

                if (!System.IO.Directory.Exists(ImageStoragePath + PropertyRefNo))
                    System.IO.Directory.CreateDirectory(ImageStoragePath + PropertyRefNo);

                resized.Save(ImageStoragePath + PropertyRefNo + "\\" + fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                Console.WriteLine("Icon: " + fileName);
            }
        }
    }
}

现在对于某些图像(https://www.mylorealestate.com/stuff/property_watermark_images/property_image_9790149681555838146.jpg),它在GetImageData函数中给出了错误。错误包含在下面。

System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.Http.WinHttpException: The server returned an invalid or unrecognized response     
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()     at System.Threading.Tasks.RendezvousAwaitable`1.GetResult()     at 
System.Net.Http.WinHttpHandler.<StartRequest>d__105.MoveNext()     --- End of inner exception stack trace ---     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)     at 
System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()     
at System.Net.Http.HttpClient.<FinishSendAsyncBuffered>d__58.MoveNext()  --- End of stack trace from previous location where exception was thrown ---     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()     at 
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)     
at DubaiRent.Core.ImageUtilities.<GetImageData>d__9.MoveNext() in D:\Projects\Web\App.Core\ImageUtilities.cs:line 247  
--- End of stack trace from previous location where exception was thrown ---     
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()     
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)     
at DubaiRent.Core.Implementation.XmlPropertyManager.<UploadImage>d__5.MoveNext() in D:\Projects\Web\App.Core\Implementation\XmlPropertyManager.cs:line 582

更新: 对于此工作图像URL,它返回null

https://watermark.propspace.com/watermark?c_id=1049&l_id=1576257625548605&aid=1464510&id=15189030190082803&wmt=1521113471&image=25_03_2018-15_34_18-1049-fe5df232cafa4c4e0f1a0294418e5660.jpeg

enter image description here

对于其余图像,它返回到响应以下

enter image description here

更新enter image description here

0 个答案:

没有答案