2013-02-18 61 views
1

以下代码在CF10上正常工作。cfhttp返回415 CF9上不受支持的介质类型

httpSvc = New http(); 
httpSvc.setMethod("post"); 
httpSvc.setCharset("utf-8"); 
httpSvc.setUrl(svcLocation); 
httpSvc.setClientCert(certLocation); 
httpSvc.setClientCertPassword(certPassword); 
httpSvc.addParam(type="body", name="body",value=requestParameters); 
result = httpSvc.send().getPrefix(); 

requestParameters的值是:

<?xml version="1.0" encoding="UTF-8"?> 
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> 
<S:Body> 
<ns2:processCreditCard xmlns:ns2="urn:com.qvalent.payway.api"> 
<requestParameters>customer.orderNumber=5396&amp;card.CVN=070&amp;order.amount=101&amp;customer.merchant=xxxx&amp;card.expiryMonth=08&amp;card.expiryYear=20&amp;order.ECI=SSL&amp;card.PAN=0000000000000008&amp;card.currency=AUD&amp;customer.username=xxxxxx&amp;order.type=capture&amp;customer.password=xxxxxxx</requestParameters> 
</ns2:processCreditCard> 
</S:Body> 
</S:Envelope> 

然而,当我把它放在一个CF9服务器上,响应FileContent是空的,我碰到下面的状态代码:

415 Unsupported Media Type 

以下是显示完整回复的链接:http://www.onoffezy.com/_testing/gateway/

Trawling G oogle,415状态码指出客户端请求的MIME类型在服务器上不可用。但是我找不到可以为请求设置MIME类型的任何地方。在cf9和cf10之间,默认的mimetype有没有区别?

我仔细看过两个版本的文档,但找不到可以解释这个问题的差异。

如果任何人都可以对此有所了解,并让我知道我需要在CF9上做什么不同,我将非常感激。

非常感谢

回答

1

感谢所有帮助。我发现了这个问题。

httpSvc.addParam(type="body", name="body",value=requestParameters); 

需要改为:

httpSvc.addParam(type="xml", name="body",value=requestParameters); 

似乎CF9发送类型=“主体”通过如二进制,但CF10将其作为一个字符串,或工程出它是xml和手柄它是这样的。一旦我将类型更改为'xml',cf9开始以xml字符串形式发送它,而不是二进制。

+0

很高兴你明白了。 – 2013-02-20 13:09:47

0

虽然我不能肯定这将解决你的问题说,你有没有尝试过的“接受”请求头设置为内容类型的反应呢?

例如:

acceptType = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" httpSvc.addParam(name="Accept", value=acceptType, type="header");

+0

感谢stinkyfriend。按照你的建议尝试,但同样的回应。我已添加链接以查看原始问题中的完整回复..也许还有别的东西。谢谢 – Jason 2013-02-19 09:03:37

0

按照documentation heretype="body"指定HTTP请求的主体。 ColdFusion不会自动设置内容类型标题或URL编码正文内容。要指定内容类型,请使用type = header的单独cfhttpparam标记。所以也许这将有助于为您的请求指定此标头。

喜欢的东西:

httpSvc.addParam(type="header", name="Content-Type", value="application/x-www-form-urlencoded"); 

您没有提供您的主体内容的一个例子。您可能需要针对特定​​内容类型的价值进行调整。 Here is a list of the available MIME types

您的示例中的变量requestParamaters中的单词参数拼写错误。它的价值是什么?

+0

嗨米格尔,我认为你让我专注于正确的领域。当我设置Content-Type时,我现在也得到了与cf10相同的错误。对于cf9和cf10来说都是相同的错误。所以朝着正确的方向前进。我正在发送SOAP XML,所以应对其他值(例如application/soap + xml),但仍然获得'415 Unsupported Media Type'。 – Jason 2013-02-19 22:25:06

+0

另外,我在原始问题中包含了requestParamaters的值。谢谢!! – Jason 2013-02-19 22:29:21

相关问题