Results 1 to 4 of 4

Thread: cJsonHttpTransfer content type not set when Request json is blank

  1. #1
    Join Date
    Feb 2009
    Location
    Adelaide, South Australia
    Posts
    2,863

    Default cJsonHttpTransfer content type not set when Request json is blank

    Hi

    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
    https://docs.microsoft.com/en-us/gra...st-mailfolders

    I think that in cJsinbHttpTransfer.pkg this should be fixed:
    Code:
       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
            End
            Get HttpVerbAddrRequest sFilePath aJson iLen False sVerb to bOK
            Function_Return bOk
       End_Function
    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:
    Code:
    {  "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;IEEE754Compatible=false, application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=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
    Marco
    Marco Kuipers
    DataFlex Consultant
    28 IT Pty Ltd - DataFlex Specialist Consultancy
    DataFlex Channel Partner for Australia and Pacific region
    Adelaide, South Australia
    www.28it.com.au

  2. #2
    Join Date
    Mar 2009
    Location
    Beech Hill - a village near Reading in the UK
    Posts
    2,812

    Default Re: cJsonHttpTransfer content type not set when Request json is blank

    Marco

    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!

    Mike

  3. #3
    Join Date
    Feb 2009
    Location
    Stuart, FL
    Posts
    5,321

    Default Re: cJsonHttpTransfer content type not set when Request json is blank

    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
    Michael Salzlechner
    StarZen Technologies, Inc
    http.://www.starzen.com

    IT Director at Balloons Everywhere

    Development Blog
    http://www.salzlechner.com/dev

    DataFlex Package Manager (aka Nuget for DataFlex)
    http://windowsdeveloper.com/dfPackage

  4. #4
    Join Date
    Feb 2009
    Location
    Adelaide, South Australia
    Posts
    2,863

    Default Re: cJsonHttpTransfer content type not set when Request json is blank

    Sorry guys

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

    Cheers
    Marco
    Marco Kuipers
    DataFlex Consultant
    28 IT Pty Ltd - DataFlex Specialist Consultancy
    DataFlex Channel Partner for Australia and Pacific region
    Adelaide, South Australia
    www.28it.com.au

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •