How to get the url response values in Asp.NET
You can use the HttpWebRequest and HttpWebResponse classes (via using System.Net
)to achieve this;
HttpWebRequest webRequest =
WebRequest.Create("https://api.twitter.com/1/users/profile_image?screen_name=twitterapi&size=bigger") as HttpWebRequest;
webRequest.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response = webRequest.GetResponse() as HttpWebResponse;
string url = response.ResponseUri.OriginalString;
url now contains the string "https://si0.twimg.com/profile_images/1438634086/avatar_bigger.png"
You can also do it using HttpClient:
public class UriFetcher
{
public Uri Get(string apiUri)
{
using (var httpClient = new HttpClient())
{
var httpResponseMessage = httpClient.GetAsync(apiUri).Result;
return httpResponseMessage.RequestMessage.RequestUri;
}
}
}
[TestFixture]
public class UriFetcherTester
{
[Test]
public void Get()
{
var uriFetcher = new UriFetcher();
var fetchedUri = uriFetcher.Get("https://api.twitter.com/1/users/profile_image?screen_name=twitterapi&size=bigger");
Console.WriteLine(fetchedUri);
}
}
I'm not exactly sure what you are asking.
I think you can use WebClient.DownloadData
in c# to call that url. Once you download the file, you can then place it in the database.
byte[] response = new System.Net.WebClient().DownloadData(url);
Download a file over HTTP into a byte array in C#?
EDIT: THIS IS WORKING FOR ME
WebRequest request = WebRequest.Create("https://api.twitter.com/1/users/profile_image?screen_name=twitterapi&size=bigger");
WebResponse response = request.GetResponse();
Console.WriteLine(response.ResponseUri);
Console.Read( );
from A way to figure out redirection URL
EDIT: THIS IS ANOTHER METHOD I THINK...using show.json from Read the absolute redirected SRC attribute URL for an image
http://api.twitter.com/1/users/show.json?screen_name=twitterapi