我是C#的新手,我正在尝试向网络上的IP电话执行GET请求以远程拨打号码。我收到一个例外,我不确定如何确定原因,因为我无法检索任何错误代码。这是我正在使用的代码: -
// Create a new HttpClient instance
var client = new HttpClient();
// Command to dial number
string dial = "http://xxx.xxx.x.x/command.htm?number=4553535345354";
try
{
// Response
HttpResponseMessage response = new HttpResponseMessage();
response = await client.GetAsync(dial);
if (response.IsSuccessStatusCode)
{
// Do other things
}
else
{
MessageBox.Show(response.StatusCode.ToString());
}
}
catch (Exception err)
{
MessageBox.Show("Could not call: " + err.Message);
}
当我运行此代码时,我收到捕获的异常,并显示消息“发送此请求时出错”。关于异常,我能看到的唯一其他附加信息是“mscorlib.dll中出现'System.Net.Http.HttpRequestException'类型的第一次机会异常”
*已更新*
无法调用:System.Net.Http.HttpRequestException:错误 发送请求时发生。 ---> System.Net.WebException:The 底层连接已关闭:连接已关闭 出乎意料。
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult) asyncResult)
在 System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
---内部异常堆栈跟踪结束---
在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)
在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)
在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
在AutoDialer.Form2.d__0.MoveNext()中 c:\ Form2.cs:第175行
**更新了26/14 Fiddler结果**
HTTP/1.1 302 Moved Temporarily Location
违反协议的报告: -
79 The Server did not return properly-formatted HTTP Headers. Maybe missing altogether (e.g. HTTP/0.9), maybe only \r\r instead of \r\n\r\n?
扩展检查: -
182 [HTTPLint] With rare exceptions, servers MUST include a DATE response header. RFC2616 Section 14.18