我试图在 Windows 应用商店应用程序上发送 POST 请求。我试图用 Fiddler 或 Charles 来捕捉它。
- Fiddler/Charles 关闭后,一切正常。
- 打开 Fiddler/Charles,PostAsync()引发异常
这是我的尝试:
Uri uri = new Uri("http://example.com");
using (StringContent content = new StringContent("{}", Encoding.UTF8, "application/json"))
{
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Host = uri.Host;
try
{
using (HttpResponseMessage response = await client.PostAsync(uri, content))
{
if (response.IsSuccessStatusCode)
{
String result = await response.Content.ReadAsStringAsync();
return result;
}
return null;
}
}
catch (Exception ex)
{
return null;
}
}
}
为什么我无法使用 fiddler 或 Charles 来分析流量?这是我得到的例外:
Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
HelpLink null string
HResult -2146233088 int
InnerException {"The underlying connection was closed: Unable to connect to the remote server."} System.Exception {System.Net.WebException}
IPForWatsonBuckets 206848215 System.UIntPtr
IsTransient false bool
Message "An error occurred while sending the request." string
RemoteStackTrace null string
Source "mscorlib" string
StackTrace " at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at Example.Services.ExampleServices.<ExampleClass>d__3.MoveNext() in c:\\TFS\\Example\\ExampleMain\\Example\\Services\\ExampleServices.cs:line 110" string
TargetSite {Void Throw()} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
WatsonBuckets null object