我想确保那些知道以下代码行是否只会获取请求的响应类型而不加载完整内容的人,因为我必须在我的应用程序中对响应类型有一些条件,我不想浪费时间对于那些应该被忽略的资源。
request = (HttpWebRequest)System.Net.HttpWebRequest.Create(url);
response = (HttpWebResponse)request.GetResponse();
var responseType = response.ContentType;
Method
将属性设置为可能是最简单的"HEAD"
- 这样您就不会获得实际内容,而只会获得标题。
另一方面,这确实意味着当您确实想要内容时需要提出两个请求......
Please use below code to get the data in response string
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "GET";
request.ContentType = "application/json";
try
{
WebResponse webResponse = request.GetResponse();
using (Stream webStream = webResponse.GetResponseStream())
{
if (webStream != null)
{
using (StreamReader responseReader = new StreamReader(webStream))
{
string response = responseReader.ReadToEnd();
JObject objjson = JObject.Parse(response);
var obj= (from p in objjson["YourobjectList"].Children()
select p).ToList();
}
}
}
}
catch (Exception ex)
{
}