简体   繁体   English

C#-Tumblr头像请求

[英]c# - Tumblr avatar request

I'm trying to get the url of a tumblr user's avatar . 我正在尝试获取tumblr用户头像的网址。 The problem is, what I get back is not the url, but the image itself. 问题是,我得到的不是URL,而是图像本身。 This is the link from which I should get the url: 这是我应该从中获得网址的链接:

api.tumblr.com/v2/blog/{blog-identifier}/avatar[/size] api.tumblr.com/v2/blog/{blog-identifier}/avatar[/size]

This is how I tried to get the url of the avatar. 这就是我尝试获取头像的网址的方式。 Note : "item" here is a blog (eg: blog.tumblr.com) 注意:这里的“项目”是一个博客(例如:blog.tumblr.com)

WebRequest req = WebRequest.Create("http://api.tumblr.com/v2/blog/" + item + "/avatar/");
WebResponse res = req.GetResponse();
StreamReader rd = new StreamReader(res.GetResponseStream(),Encoding.ASCII);
var end = rd.ReadToEnd();

I read an response on a forum which said : 我在一个论坛上读了一个回应,说:

the /avatar route redirects you to the avatar url. / avatar路由会将您重定向到头像网址。

Don't follow the redirect and pull the url out of the Location header or the body of the request, which contains the same url. 不要遵循重定向并将URL从Location标头或包含相同URL的请求正文中拉出。

But I don't know how to do that, can you help me ? 但是我不知道该怎么做,你能帮我吗? There are some answers to some similar questions to mine, but those are for a different programming language.. 对于一些类似的问题,我有一些答案,但是它们是针对另一种编程语言的。

WebRequest req = WebRequest.Create("http://api.tumblr.com/v2/blog/" + item + "/avatar/");
            WebResponse res = req.GetResponse();
            string avatarUrl = res.ResponseUri.ToString();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM