HttpWebRequest的不发送的UserAgent [英] HttpWebRequest not sending UserAgent

查看:486
本文介绍了HttpWebRequest的不发送的UserAgent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来寻找.NET的整个Web一面,我碰到一个轻微的问题。

I'm new to looking at the whole Web side of .net, and I've run into a slight issue.

我试图做的HttpWebRequest如下:

I'm trying to do a HttpWebRequest as below:

String uri = "https://skyid.sky.com/signup/";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";
request.Method = "GET";
request.GetResponse();



当URI是指向HTTPS站点。但是,一旦我看看这个提琴手,它已经打消了我的UserAgent,只显示主机和连接:保持活动

Where the uri is pointing to a HTTPS site. But once I look at this in Fiddler, it has removed my UserAgent and only shows Host and Connection: Keep-Alive.

CONNECT skyid.sky.com:443 HTTP/1.1
Host: skyid.sky.com
Connection: Keep-Alive

这是正常使用HTTPS或者我只是失去了一些东西?也许我甚至缺少小提琴手的东西,它没有显示这个给我。

Is this normal with HTTPS or am I simply missing something? Maybe I'm even missing something in Fiddler that it's not showing this to me.

任何帮助将不胜感激,谢谢大家!

Any help will be appreciated, thanks all!

推荐答案

我不要以为你正在寻找正确的提琴手线。你已经证明是一个连接动词,而不是 GET 。在的UserAgent 应使用 request.UserAgent 属性来设置正确。调试请求另一种方法是配置网络在应用程序层面,我个人比较喜欢跟踪提琴手:

I don't think that you are looking at the correct Fiddler line. What you have shown is a CONNECT verb, not GET. The UserAgent should be properly set using the request.UserAgent property. Another way to debug the request is to configure network tracing at your application level which I personally prefer compared to Fiddler:

<configuration>
    <system.diagnostics>
        <sources>
            <source name="System.Net" tracemode="protocolonly" maxdatasize="1024">
                <listeners>
                    <add name="System.Net"/>
                </listeners>
            </source>
        </sources>
        <switches>
            <add name="System.Net" value="Verbose"/>
        </switches>
        <sharedListeners>
            <add 
                name="System.Net"
                type="System.Diagnostics.TextWriterTraceListener"
                initializeData="network.log"
            />
        </sharedListeners>
        <trace autoflush="true"/>
    </system.diagnostics>
</configuration>

这篇关于HttpWebRequest的不发送的UserAgent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆