3

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

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();

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

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!

4

1 回答 1

7

我不认为您正在查看正确的 Fiddler 行。您所显示的是CONNECT动词,而不是GET. UserAgent应该使用该属性正确设置request.UserAgent。调试请求的另一种方法是在您的应用程序级别配置网络跟踪,与 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>
于 2012-08-14T16:41:10.433 回答