Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 8 使用fiddler捕获windows应用商店应用程序流量会引发异常_Windows 8_Visual Studio 2012_Windows Store Apps_Fiddler_Charles Proxy - Fatal编程技术网

Windows 8 使用fiddler捕获windows应用商店应用程序流量会引发异常

Windows 8 使用fiddler捕获windows应用商店应用程序流量会引发异常,windows-8,visual-studio-2012,windows-store-apps,fiddler,charles-proxy,Windows 8,Visual Studio 2012,Windows Store Apps,Fiddler,Charles Proxy,我已尝试在Windows应用商店应用程序上发送POST请求。我试图用Fiddler或Charles来捕捉它 关闭Fiddler/Charles后,一切正常 打开Fiddler/Charles后,PostAsync()会引发异常 以下是我的尝试: Uri uri = new Uri("http://example.com"); using (StringContent content = new StringContent("{}", Encoding.UTF8, "application/j

我已尝试在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
Data{System.Collections.ListDictionaryInternal}System.Collections.IDictionary{System.Collections.ListDictionaryInternal}
帮助链接空字符串
HResult-2146233088 int
InnerException{“基础连接已关闭:无法连接到远程服务器。”}System.Exception{System.Net.WebException}
IPFORWATSON206848215系统。UIntPtr
非暂时性假布尔
消息“发送请求时出错。”字符串
RemoteStackTrace空字符串
源“mscorlib”字符串
StackTrace“在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n在System.Runtime.CompilerServices.TaskAwaiter.ThrowForOnSuccess(任务任务任务)\r\n在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务任务)在System.Runtime.CompilerServices.TaskAwaiter\n\r\n在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n在c:\\TFS\\Example\\ExampleMain\\Example\\Services\\ExampleServices.cs:line 110“字符串中
TargetSite{Void Throw()}System.Reflection.MethodBase{System.Reflection.RuntimeMethodInfo}
WatsonBuckets空对象

您是否忘记为您的申请授予许可


您是否忘记将计算机配置为信任Fiddler的根证书?

我找到了问题的根源和解决方案:不能手动定义主机头,以便请求在Fiddler或Charles处于活动状态的环境中工作

这意味着我们必须删除或注释掉以下行:

client.DefaultRequestHeaders.Host = uri.Host;
通过不自行设置主机,神奇的是,您的应用程序将再次与本地代理一起工作,框架将自行设置主机头

这对于那些可能在错误之处遵循了最近的Microsoft指南的人来说非常有用:

我没有忘记这两个设置中的任何一个。问题来源于其他地方:如果您需要本地代理,则配置
DefaultRequestHeaders.Host
自己似乎是被禁止的。看到我的答案了吧,太棒了。这可能源于试图支持使用主机头控制DNS解析而不依赖URL的主机的可怕模式(在RFC2616中这是非法的)。正在跟进.NET团队。您知道请求失败的原因吗?您的环境是否需要其他代理?@EricLaw我所能提供的最好信息是问题中的例外详细信息。不,我没有任何其他代理,windows防火墙已关闭。一个朋友甚至在另一台电脑上试过,结果是同一个问题。谢谢你的解决方案!!我的头撞到了墙上,想弄明白为什么它不让小提琴手跑就行了!