View Full Version : cJsonHttpTransfer content type not set when Request json is blank

3-Dec-2019, 07:38 PM

The following Microsoft Graph api is one of many that does not have a body, but does expect the content type to be set toe application/json

I think that in cJsinbHttpTransfer.pkg this should be fixed:

Function HttpVerbJsonAddrExec String sHost String sFilePath Address aJson Integer iLen String sVerb Returns Boolean Boolean bOk
Integer iError
String sContentType

Send ClearDataReceived // this should be zero, just in case it is not
Set psRemoteHost to sHost
// You need to clear headers between posts. If you need to set custom headers you should
// set pbClearHeaders to false and then manually send ClearHeaders and AddHeaders in your code
If (pbClearHeaders(Self)) ;
Send ClearHeaders

Get psContentTypeSent to sContentType
If (iLen > 0 and sContentType <> "") Begin
Get AddHeader "Content-Type" sContentType to bok
Get HttpVerbAddrRequest sFilePath aJson iLen False sVerb to bOK
Function_Return bOk

Obviously iLen would be 0, and thus it does not set the content type. I think that the "If (iLen > 0 and sContentType <> "") Begin" should be changed to "If (iLen > 0 OR sContentType <> "") Begin"

btw the error returned is:

{ "error": {
"code": "BadRequest",
"message": "A supported MIME type could not be found that matches the acceptable MIME types for the request. The supported type(s) 'application/json;odata.metadata=minimal;odata.streaming=true;I EEE754Compatible=false, application/json;odata.metadata=minimal;odata.streaming=true;I EEE754Compatible=true, application/json;odata.metadata=minimal;odata.streaming=true, application/json;odata.metadata=minimal;odata.streaming=false; IEEE754Compatible=false, application/json;odata.metadata=minimal;odata.streaming=false; ...

Kind regards

Mike Peat
4-Dec-2019, 06:10 AM

Actually, if I'm reading you correctly, it is Microsoft you should be reporting the error to. Requiring content-type to be set when there is no content is an obvious error (and, without looking it up, I'd guess a clear violation of the RFCs). Not that they'll do anything about it of course - they are a law unto themselves - but at least they should be made aware so they can cringe in shame! :)


4-Dec-2019, 06:48 AM
have not come across any rule that would say you cant require a content type on a request without content. But i did come across a number of APIs that require a content type no matter what.

Does it make sense, no, but of course a client should be able to provide what the server expects within reason of course

if i remember correct, axios had a similar issue but they do have a workaround for this and possibly it is fixed already as well

8-Dec-2019, 06:11 PM
Sorry guys

False alarm. The issue was resolved with this one
Get AddHeader "Accept" "*/*" to bOk