不允许分块的服务器的 HttpWebRequest 不起作用
我有一些 Java Web 服务 (Https) 的 C# 存根(在 Visual Studio 2008、.NET 2.0 中创建)。 服务器不允许对请求进行分块。 我能够在 HttpWebRequest 中将 sendChunked 设置为 false。
当我调用网络服务方法时,只有很少的数据通过网络,它们工作得很好。
但是,当我发送包含大量数据的请求时,我收到“无法解析请求”错误。
这里有两个奇怪的事情:
- 通过将 HttpConstants.CHUNKED 设置为 false,这可以通过 Java 正常工作,如果不这样做,它会因相同的“无法解析请求错误”而中断。
- 如果我有小提琴手在后台运行,一切正常?! 我相信这是由于 Fiddler 在发送请求字节之前缓冲了它们。 注意:如果我关闭 Fiddler 选项“解密 HTTPS”,它就会停止工作。
I have some C# stubs to a Java web service (Https) (created in Visual Studio 2008, .NET 2.0).
The server does not allow requests to be chunked.
I was able to set sendChunked to false in the HttpWebRequest.
When I call web service methods which have very little data going across the wire they work fine.
However, when I send requests which contain a significant amount of data, I get an "unable to parse request" error.
Here's the two strange things:
- This works fine through Java by setting the HttpConstants.CHUNKED to false, and if you don't do that it breaks with the same "Unable to parse request error".
- If I have fiddler running in the background everything works fine?! I believe this is due to Fiddler buffering the request bytes before sending them off. NOTE: if I turn off the Fiddler option to "Decrypt HTTPS" it stops working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
啊,经典的“通过观察改变行为”。 问题在于,正如您所指出的,Fiddler 本身会进行大量缓冲等操作。 一种选择可能是(暂时)关闭 HTTPS,并使用 Wireshark 等被动网络嗅探工具来查看是否.NET 遵循您所设置的设置。
Ah, the classic "changing the behavior by observing it". The problem is that, as you point out, Fiddler does a bunch of buffering and the like itself. One option may be turning HTTPS off (temporarily), and using a passive network sniffing tool like Wireshark to see if .NET is obeying the settings you're setting.
从你的描述中我不清楚你所说的“存根”是什么意思。 您的意思是您已经创建了对 Java 服务的 Web 引用吗?
如果是这样,您可以重写
GetWebRequest
方法以返回您自己的 HttpWebRequest,并将SendChunked
属性设置为 false:如果这不是您所要求的,请澄清。
I'm not clear from your description what you mean by "stubs". Do you mean that you've created a Web Reference to the Java service?
If so, you can override the
GetWebRequest
method to return your own HttpWebRequest with theSendChunked
property set to false:If this is not what you're asking, then please clarify.
我解决了这个问题。
看起来当我在 Visual Studio 中使用“添加 Web 引用”创建 Web 服务方法的存根时,它正在向 Web 请求添加一些内容,这使服务器不满意。
我编写了自己的方法,该方法从头开始创建 XML 并发送 Web 请求,而不使用任何存根,而且效果很好。
我讨厌这样的问题。
I resolved this issue.
Looks like when I create the stubs to the web service methods using "add a web reference" in visual studio it is adding something to the web request which was making the server unhappy.
I wrote my own method which creates the XML from scratch and sends the web request without using any of the stubs and it works fine.
I hate problems like this.