处理不正确的HTTP标头正文大小值? [英] Dealing with incorrect HTTP header body size values?

查看:215
本文介绍了处理不正确的HTTP标头正文大小值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用C#ASP.NET MVC,在Magento网站上调用Web服务时:

Using C# ASP.NET MVC, when calling a webservice on a Magento site:

有时,Magento网站会发送错误的HTTP标头,特别是正文大小的标头说身体比实际大。例如,它可能会说body-size = 1000,但是主体只包含999个字节。尽管标题不正确,但正文仍然正确,所以我仍然希望能够处理它。

Sometimes a Magento site will send wrong HTTP headers, specifically the body-size header saying that the body is bigger than it really is. For example it might say body-size=1000, but the body only consists of 999 bytes. Despite the header being incorrect, the body is correct so I would still like to be able to process it.

现在当我尝试在C#中读取该响应时

Now when I try to read that response in C#

var invoiceInfo = _magentoService.salesOrderInvoiceInfo(sessionId, invoiceId);

它抛出异常:

Connection closed by remote host

这是有道理的,因为它的尝试读取第1000个字节但不存在。更糟糕的是,读取正文的代码深埋在.NET框架中,所以我无法改变它:

Which makes sense kindof, because its trying to read the 1000th byte but its not there. And to make it worse, the code that reads the body is buried deep within the .NET framework, so I cant change it:

[System.Web.Services.Protocols.SoapRpcMethodAttribute("urn:Mage_Api_Model_Server_V2_HandlerAction", RequestNamespace="urn:Magento", ResponseNamespace="urn:Magento")]
[return: System.Xml.Serialization.SoapElementAttribute("result")]
public salesOrderInvoiceEntity salesOrderInvoiceInfo(string sessionId, string invoiceIncrementId) {
    object[] results = this.Invoke("salesOrderInvoiceInfo", new object[] {
                sessionId,
                invoiceIncrementId}); // exception thrown here
    return ((salesOrderInvoiceEntity)(results[0]));
}

我无法更改Magento网站,或修复导致此问题的任何问题(它是第三方网络服务器)。

I can't change the Magento site, or fix whatever problem is causing this (its a 3rd parties webserver).

我可以做些什么来改变我自己的C#代码的行为?我希望能够以某种方式强制它在到达身体末端时停止并在出现这种情况时忽略此异常

Is there anything I can do to change the behavior of my own C# code? I would like to be able to somehow force it to stop when it reaches the end of the body and ignore this exception if this case arises

推荐答案

从此处尝试解决方案(将API端点更改为api.php): stackoverflow.com/a/36200828/1936722

Try solution from here (changing API endpoint to api.php): stackoverflow.com/a/36200828/1936722

基本上更改API网址:

domain.com/index.php/api/v2_soap/index/wsdl / 1

Basically change the API url from:
domain.com/index.php/api/v2_soap/index/wsdl/1

to:

domain.com / api / v2_soap /?wsdl = 1

这篇关于处理不正确的HTTP标头正文大小值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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