クラス IWebProxy を実装して次のようにすることで、プロキシを使用できます。
aHandler.UseCookies = true;
aHandler.AllowAutoRedirect = true;
IWebProxy proxy = new AWProxy(new Uri("http://xx.xx.xxx.xxx:xxxx"));
proxy.Credentials = new NetworkCredential("xxxx", "xxxx");
aHandler.Proxy = proxy;
HttpClient client = new HttpClient(aHandler);
client.GetAsync(" http://google.com ") を呼び出すことで、成功した応答メッセージを返すことができました。ただし、ヘッダーとコンテンツのポスト/プットを制御するために HttpRequestMessage を使用できるようにしたいと考えています。
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, uri);
//add other headers
requestMessage.Headers.UserAgent.ParseAdd("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)");
HttpResponseMessage response = await client.SendAsync(requestMessage);
しかし、HttpRequestMessage を使用すると、次の例外が発生します。
System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: Unable to connect to the remote server. ---> System.NullReferenceException: Object reference not set to an instance of an object.
どんな助けでも大歓迎です、ありがとう!