获取响应的内容类型,而无需加载整个内容
本文关键字:加载 响应 类型 获取 | 更新日期: 2023-09-27 17:49:24
我想确保从那些谁知道如果下面的代码行将只获得请求的响应类型而不加载完整的内容,因为我必须在我的应用程序响应类型的一些条件下,我不想浪费时间的资源,应该被忽略。
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)
{
}