2013-02-18 64 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

相關問題