cfhttp返回415 CF9上不受支持的介质类型
以下代码在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&card.CVN=070&order.amount=101&customer.merchant=xxxx&card.expiryMonth=08&card.expiryYear=20&order.ECI=SSL&card.PAN=0000000000000008&card.currency=AUD&customer.username=xxxxxx&order.type=capture&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上做什么不同,我将非常感激。
非常感谢
感谢所有帮助。我发现了这个问题。
httpSvc.addParam(type="body", name="body",value=requestParameters);
需要改为:
httpSvc.addParam(type="xml", name="body",value=requestParameters);
似乎CF9发送类型=“主体”通过如二进制,但CF10将其作为一个字符串,或工程出它是xml和手柄它是这样的。一旦我将类型更改为'xml',cf9开始以xml字符串形式发送它,而不是二进制。
虽然我不能肯定这将解决你的问题说,你有没有尝试过的“接受”请求头设置为内容类型的反应呢?
例如:
acceptType = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" httpSvc.addParam(name="Accept", value=acceptType, type="header");
感谢stinkyfriend。按照你的建议尝试,但同样的回应。我已添加链接以查看原始问题中的完整回复..也许还有别的东西。谢谢 – Jason 2013-02-19 09:03:37
按照documentation here的type="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
中的单词参数拼写错误。它的价值是什么?
很高兴你明白了。 – 2013-02-20 13:09:47