System.Net.WebRequest req = System.Net.WebRequest.Create(URL);
req.Proxy = null;
System.Net.WebResponse resp = req.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
string result = sr.ReadToEnd().Trim();
我有這樣的代碼,它會在我的URL上發出GET請求並返回JSON數據。但是,我也需要從中獲取標題值。該URL的如何獲取GET請求中的標題值?
輸出示例如下:
Content-Type: application/json
Content-Language: en
Expires: Sat, 01 Jan 2000 00:00:00 GMT
Vary: Cookie, Accept-Language
Pragma: no-cache
Cache-Control: private, no-cache, no-store, must-revalidate
Set-Cookie: csrftoken=66161e4f97cbf771199ff78cfeea835e; expires=Sat, 20-Feb-2016 06:49:03 GMT; Max-Age=31449600; Path=/
Set-Cookie: mid=VOgqXwABAAHBumwiwEqLc2ScukeD; expires=Fri, 16-Feb-2035 06:49:03 GMT; Max-Age=630720000; Path=/
Connection: close
Content-Length: 108
{"status":"ok","shift":18,"header":"638wprvx7lg5Um0dZzBAKfjIkML12ChQ","edges":100,"iterations":10,"size":42}
使用我的代碼,我能得到最後的JSON數據返回,但我也需要頭。我怎樣才能做到這一點?謝謝。