Head request with HttpClient

这一生的挚爱 提交于 2019-12-20 05:15:07

问题


I'm trying to make a HEAD request to Google.com.

This is my code:

using (var client = new HttpClient()) 
{
    var m = new HttpRequestMessage(HttpMethod.Head, "http://google.com");

    var resp = await client.SendAsync(m);
    return true;
}

When I execute this code I get the following exception:

System.Net.WebException: The request requires buffering data to succeed.
at System.Net.HttpWebRequest.Redirect (System.Net.WebAsyncResult result, HttpStatusCode code, System.Net.WebResponse response) [0x00000] in :0
at System.Net.HttpWebRequest.CheckFinalStatus (System.Net.WebAsyncResult result) [0x00000] in :0
at System.Net.HttpWebRequest.SetResponseData (System.Net.WebConnectionData data) [0x00000] in :0

I can't understand why... Google accept Head requests because using Postman I get a 200 OK code

Can you help me?

来源:https://stackoverflow.com/questions/25509233/head-request-with-httpclient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!