我尝试从WebAPI服务器获取png图像

时间:2018-12-03 11:28:38

标签: c# image xamarin

我正在尝试从服务器下载png图像,但是它不起作用。我的响应是HTTP 200 OK

我得到:

Screen

标题:

Cache-Control: public, max-age=86400 
Connection: Keep-Alive 
Date: Fri, 30 Nov 2018 12:32:08 GMT 
Keep-Alive: timeout=5, max=99
OkHttp-Received-Millis: 1543581128745 
OkHttp-Selected-Protocol: http/1.1 
OkHttp-Sent-Millis: 1543581128514 Server: Apache/2.4.33 (Amazon) OpenSSL/1.0.2k-fips PHP/7.0.30 X-Powered-By: PHP/7.0.30
Content-Length: 26190 
Content-Type: image/png 
Keep-Alive: timeout=5, max=99 
OkHttp-Received-Millis: 1543581128745 
OkHttp-Selected-Protocol: http/1.1 
OkHttp-Sent-Millis: 1543581128514 
X-Powered-By: PHP/7.0.30 

代码:

public async Task<Image> GetAvatar(string dpi, Int64 uin)
{
    var response = await BasicRequestAsync(string.Format(AVATAR_URL, dpi, uin), HttpMethod.Get, true, null, null, false);

    if (response == null) 
         return null;

    var stream = await response.Content.ReadAsByteArrayAsync();

    Image image = new Image();

    image.Source = ImageSource.FromStream(() => new MemoryStream(stream));

    return image;
}

服务器:HEADERS:

  

IMToken:123123123 uin:123 user-agent:...

     

返回标题内容类型为image / png的未打包图像

VM:

 private Image _avatarImage;
        public Image AvatarImage
        {
            get => _avatarImage;
            set
            {
                if(_avatarImage == value) return;
                _avatarImage = value;
                OnPropertyChanged();
            }
        }
        #endregion

        #region Methods
        public AvatarPageViewModel(INavigation navigation) : base(navigation)
        {
            InitializeAvatarData();
        }

        private async void InitializeAvatarData()
        {
            var result = AvatarManagerInstance.GetAvatar(DependencyService.Get<IDisplayInfo>().GetDisplayDpi(), 1);
        }

0 个答案:

没有答案