C# 获取url 状态,获取重定向(HttpWebRequest)

本文提供了网易云音乐的PC版本及OSX版本的最新下载链接,并通过实例展示了如何使用HttpWebRequest来检查网页的状态码,这对于确保下载链接的有效性至关重要。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

网易云音乐下载

music.163.com/api/pc/download/latest

 http://tool.chinaz.com/pagestatus/?url=music.163.com/api/pc/download/latest

pc版本下载 http://tool.chinaz.com/pagestatus/?url=music.163.com%2Fapi%2Fpc%2Fdownload%2Flatest

 

http://tool.chinaz.com/pagestatus/?url=music.163.com%2Fapi%2Fosx%2Fdownload%2Flatest

 

 

Http​Status​Code

Examples

 

The following example compares the status returned by an HttpWebResponse with a member of theHttpStatusCode class to determine the status of a response.

C# 

HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create("http://www.contoso.com");
httpReq.AllowAutoRedirect = false;

HttpWebResponse httpRes = (HttpWebResponse)httpReq.GetResponse();if (httpRes.StatusCode==HttpStatusCode.Moved) 
{
   // Code for moved resources goes here.
}

// Close the response.
httpRes.Close();
  

 

 string newUrl = httpRes.Headers["Location"];//获取重定向的网址httpRes.Headers["Location"];//获取重定向的网址
Date: Fri, 12 May 2017 13:14:12 GMT
Server: Apache
Location: http://ss.ishadowx.com/
Content-Length: 207
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1

 

Remarks

The HttpStatusCode enumeration contains the values of the status codes defined in RFC 2616 for HTTP 1.1.

The status of an HTTP request is contained in the HttpWebResponse.StatusCode property.

状态码 详情 https://docs.microsoft.com/en-us/dotnet/api/system.net.httpstatuscode?view=netcore-2.0

 

https://msdn.microsoft.com/zh-cn/library/system.net.httpstatuscode.aspx

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值