C # using HttpClient to get location

Source: Internet
Author: User

Before using HttpWebRequest, just set the HttpWebRequest object's AllowAutoRedirect property value to False to get the location in the RESPOMSE header;

But later in the use of HttpWebRequest in Silverlight, there is no allowautoredirect this attribute, a variety of points can not point out, so can only use HttpClient, the code is as follows:

1  Public stringGetLocation (stringURL)2         {3Httpclienthandler hander =NewHttpclienthandler ();4Hander. AllowAutoRedirect =false;5HttpClient client =NewHttpClient (hander);6             returnclient. Getasync (URL). Result.Headers.Location.ToString ();7}

referencing noun space System.Net.Http

C # using HttpClient to get location

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.