繁体   English   中英

HttpWebRequest vs使用SSL的Fiddler

[英]HttpWebRequest vs Fiddler using SSL

我有一个使用HttpWebRequest将一些数据发送到第三方服务的Web应用程序。 当我通过Web代码运行它时失败了,但是当我使用Fiddler的作曲器发送几乎完全相同的数据时,它就可以工作。

我之所以说“非常多”,是因为数据包含密码摘要以及随每条消息而变化的随机数和时间戳。 我已经设置了一个断点,并获取了Web应用程序即将发送的数据并将其粘贴到Fiddler中,并且它可以正常工作。

我也将代码设置为也可以通过Fiddler的代理运行,这很棒-我可以看到发送的“原始”数据-仍然失败,但是它使我能够检查标头是否完全相同并弄乱了它们一点(找不到有用的东西)。

    WebProxy myproxy = new WebProxy("127.0.0.1:8889", false);
    req.Proxy = myproxy;

我已经禁用了Fiddler的“自动身份验证”和“跟随重定向”选项(保留在“修复内容长度标头”上),以防万一其中之一导致Fiddler表现得很聪明。

这篇文章是指向https URL的,因此在解密HTTPS流量时,我确实必须添加以下行来忽略Fiddler的证书问题

    ServicePointManager
        .ServerCertificateValidationCallback +=
        (sender, cert, chain, sslPolicyErrors) => true;

有谁知道我应该启用或禁用HttpWebRequest上的任何选项以使其像Fiddler一样起作用? 由于实际内容似乎相同,因此安全性/身份验证选项可能有所不同吗?

更改Fiddler的“解密HTTPS”设置似乎没有任何影响,只是意味着我无法查看数据。

是否可以使用HttpWebRequest以外的其他选项? 还有哪些其他库不只是在后台使用HttpWebRequest? 我不需要异步,但是HttpClient是否使用更新的库来更好地处理事情?

我看过其他有关连接和使HttpWebRequest更具性能的文章,但此刻我仅发布一条消息。

如果有帮助,则标题如下所示:

POST https://www.server.com/enterprise/soap?ServiceName=PassportService&auth=1 HTTP/1.1
Content-Type: text/xml; charset=utf-8
SOAPAction: http://www.server.com/ws/passport/2008/04/PassportService#publishDocumentWithParameters
Host: vha.server.com
Content-Length: 4601
Expect: 100-continue
Connection: Keep-Alive

消息的主体只是SOAP xml

这是实现.NET网络跟踪的一些数据

System.Net Information: 0 : [8864] ConnectStream#7307007 - Sending headers
{
Content-Type: text/xml; charset=utf-8
SOAPAction: http://www.server.com/ws/passport/2008/04/PassportService#publishDocumentWithParameters
Host: vha.server.com
Content-Length: 4393
Expect: 100-continue
Connection: Keep-Alive
}.
System.Net Information: 0 : [8864] SecureChannel#63848051::.ctor(hostname=vha.server.com, #clientCertificates=0, encryptionPolicy=RequireEncryption)
System.Net Information: 0 : [8864] Enumerating security packages:
System.Net Information: 0 : [8864]     Negotiate
System.Net Information: 0 : [8864]     NegoExtender
System.Net Information: 0 : [8864]     Kerberos
System.Net Information: 0 : [8864]     NTLM
System.Net Information: 0 : [8864]     Schannel
System.Net Information: 0 : [8864]     Microsoft Unified Security Protocol Provider
System.Net Information: 0 : [8864]     WDigest
System.Net Information: 0 : [8864]     TSSSP
System.Net Information: 0 : [8864]     pku2u
System.Net Information: 0 : [8864]     CREDSSP
System.Net Information: 0 : [8864] SecureChannel#63848051 - Left with 0 client certificates to choose from.
System.Net Information: 0 : [8864] AcquireCredentialsHandle(package = Microsoft Unified Security Protocol Provider, intent  = Outbound, scc     = System.Net.SecureCredential)
System.Net Information: 0 : [8864] InitializeSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY, context = (null), targetName = vha.server.com, inFlags = ReplayDetect, SequenceDetect, Confidentiality, AllocateMemory, InitManualCredValidation)
System.Net Information: 0 : [8864] InitializeSecurityContext(In-Buffer length=0, Out-Buffer length=112, returned code=ContinueNeeded).
System.Net.Sockets Verbose: 0 : [8864] Socket#55285825::Send()

...然后有一些来回证书...

System.Net Information: 0 : [8864] SecureChannel#63848051 - Remote certificate was verified as valid by the user.
System.Net Information: 0 : [8864] ProcessAuthentication(Protocol=Tls, Cipher=Rc4 128 bit strength, Hash=Md5 128 bit strength, Key Exchange=RsaKeyX 2048 bit strength).
System.Net.Sockets Verbose: 0 : [8864] Socket#55285825::Send()

...然后是更多的东西...

System.Net Verbose: 0 : [8864] Exiting HttpWebRequest#49916336::GetRequestStream()  -> ConnectStream#7307007
System.Net Verbose: 0 : [8864] ConnectStream#7307007::Write()
System.Net Verbose: 0 : [8864] Data from ConnectStream#7307007::Write
System.Net Verbose: 0 : [8864] 00000000 : 3C 73 6F 61 70 65 6E 76-3A 45 6E 76 65 6C 6F 70 : <soapenv:Envelop

...随后将有更多的SOAP数据(看起来像加密的版本... ...加密的回复又回来了,然后被解密了...

System.Net Information: 0 : [8864] Connection#4562529 - Received status line: Version=1.1, StatusCode=401, StatusDescription=Unauthorized.
System.Net Information: 0 : [8864] Connection#4562529 - Received headers
{
Vary: Accept-Encoding
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Length: 666
Content-Type: text/xml;charset=UTF-8
Date: Thu, 07 Aug 2014 06:21:40 GMT
Server: XXXX Web Server 8
}.
System.Net Information: 0 : [8864] ConnectStream#27021036::ConnectStream(Buffered 666 bytes.)
System.Net Information: 0 : [8864] Associating HttpWebRequest#49916336 with ConnectStream#27021036
System.Net Information: 0 : [8864] Associating HttpWebRequest#49916336 with HttpWebResponse#16709290

...带有一些XML并带有一些错误信息(第3方似乎无法用来查明问题...

简短的答案是没有区别。

感谢@EricLaw的帮助,我得以排除他能想到的任何其他变量。

问题是密码摘要中的时间戳。 我的机器时间稍微缩短了,他们的时间也减少了(但是相反)。 因此结果是,当我将数据粘贴到Fiddler时,它可以正常工作,因为我稍稍延迟了(但不太多)。 对于这些请求,有一个37秒的窗口,当它从代码运行时,看起来好像是从将来到他们的服务器的时间。

当只有一个变量时,可能就是问题所在!

感谢您的耐心等待和帮助Eric。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM