Jason
Jason

Reputation: 1977

cfhttp returns 415 Unsupported Media Type on CF9

The following code is working fine on CF10.

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();

The value of requestParameters is:

<?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>

However, when I place it on a CF9 server, the response FileContent is empty and I get the following status code:

415 Unsupported Media Type

Here is a link displaying the full response: http://www.onoffezy.com/_testing/gateway/

Trawling Google, a 415 status code states that the mime type requested by the client is not available on the server. However I could not find anywhere that the mime type can be set for request. Is there a difference int he default mimetype between cf9 and cf10?

I have looked closely at the documentation for both versions, but cannot find a difference that may explain this.

If anyone can shed some light on this and let me know what I need to do differently on CF9 would be hugely appreciated.

Many Thanks

Upvotes: 2

Views: 1238

Answers (3)

Jason
Jason

Reputation: 1977

Thanks to all that helped. I found the problem.

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

needed to be changed to:

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

It appears that cf9 sends type='body' through as Binary, but cf10 sends it as a string, or works out it is xml and handles it as such. Once I changed the type to 'xml', cf9 started sending it through as a string of xml, and not binary.

Upvotes: 2

Miguel-F
Miguel-F

Reputation: 13548

According to the documentation here the type="body" specifies the body of the HTTP request. ColdFusion does not automatically set a content-type header or URL encode the body contents. To specify the content-type, use a separate cfhttpparam tag with type=header. So maybe it will help to specify this header for your request.

Something like:

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

You did not supply an example of your body content. You may have to play around with the value for your specific content type. Here is a list of the available MIME types.

You have misspelled the word parameters in the variable requestParamaters from your example. What is the value of it?

Upvotes: 1

stinkyfriend
stinkyfriend

Reputation: 986

While I can't say for certain this will solve your problem, have you tried setting the 'Accept' request header to the content type of the response?

For example:

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

Upvotes: 1

Related Questions