Skip to Content

Status 415 HTTP - XML

Hi all,

I am getting an error "The server refused this request because the request entity is in a format not supported by the requested resource for the requested method." while I send a XML file to a API.

My code:

CALL METHOD cl_http_client=>create_by_destination
EXPORTING
destination = 'INTEGRATION'
IMPORTING
client = http_client
EXCEPTIONS
argument_not_found = 1
destination_not_found = 2
destination_no_authority = 3
plugin_not_active = 4
internal_error = 5
OTHERS = 6.
IF sy-subrc <> 0.

ENDIF.


CALL METHOD http_client->request->set_header_field
EXPORTING
name = '~request_method'
value = 'POST'.

CALL METHOD http_client->request->set_header_field
EXPORTING
name = 'Content-Type'
value = 'text/xml; charset=utf-8'.

CALL METHOD http_client->request->set_cdata
EXPORTING
data = wf_string
offset = 0
length = rlength.

CALL METHOD http_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4.

CALL METHOD http_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4.

wf_string1 = http_client->response->get_cdata( ).

My XML file is:

CLEAR wf_string.
CONCATENATE wf_string
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
'<EIC_MarketDocument>'
'<mRID>' '1117' '</mRID>'
'<type>' 'B03' '</type>'
'<sender_MarketParticipant.marketRole.type>' 'A42' '</sender_MarketParticipant.marketRole.type>'
'<sender_MarketParticipant.mRID CodingScheme = "A01">' '17V' '</sender_MarketParticipant.mRID>'
'<receiver_MarketParticipant.marketRole.type>' 'A40' '</receiver_MarketParticipant.marketRole.type>'
'<receiver_MarketParticipant.mRID CodingScheme = "A01">' '17' '</receiver_MarketParticipant.mRID>'
'<revisionNumber>' '1' '</revisionNumber>'
'<createdDateTime>' '2016-07-06T16:32:38Z' '</createdDateTime>'

'<EICCode_MarketDocument>'
'<long_Names.name>' 'FR_517320' '</long_Names.name>'
'<display_Names.name>' 'FR_517320' '</display_Names.name>'

'<status> <value>A14</value> </status>'
'<attributeInstanceComponent.attribute>' 'Local' '</attributeInstanceComponent.attribute>'

'<lastRequest_DateAndOrTime.date>' '2018-02-12' '</lastRequest_DateAndOrTime.date>'

'<eICCode_MarketParticipant.aCERCode_Names.name>' '' '</eICCode_MarketParticipant.aCERCode_Names.name>'
'<eICCode_MarketParticipant.vATCode_Names.name>' '' '</eICCode_MarketParticipant.vATCode_Names.name>'
'<eICParent_MarketDocument.mRID>' '' '</eICParent_MarketDocument.mRID>'
'</EICCode_MarketDocument>'
'</EIC_MarketDocument>'
INTO wf_string .

Connexion test:

I don't know where is the problem, I did this exactly like others examples in forums.

Thanks you very much for your help!

test-con.jpg (56.0 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Feb 14 at 10:38 PM

    EDIT my answer is probably completely wrong, cf comment by Tibor below.

    In your screen shot, the error is 405 "method not allowed", and only POST is allowed (allow=POST). It means that the way you "say" POST is incorrect:

    CALL METHOD http_client->request->set_header_field EXPORTING name = '~request_method' value = 'POST'.

    Instead, use:

    http_client->request->set_method( if_http_request=>co_request_method_post ).

    PS: you made a confusion between the true HTTP request method and the SAP "pseudo-header field" ~request_method. The latter is derived automatically from the HTTP request header fields when an incoming HTTP request arrives at SAP. It's used to simplify the processing of the request by the ICF request handler.

    PS: I don't understand why you said it was an XML problem (in the request body).

    Add comment
    10|10000 characters needed characters exceeded

    • Sorry, I didn't pay attention that the screenshot originated from SM59.

      Thank you for the clarification. 424 is not clearly related to the "file format" though (wikipedia: the request failed because it depended on another request and that request failed (e.g., a PROPPATCH)).

      So, my answer was completely wrong :(

      I also probably made a mistake about set_header_field EXPORTING name='~request_method' value='POST'. It probably works with the same behavior as http_client->request->set_method( if_http_request=>co_request_method_post ).

  • Feb 14 at 11:02 AM
    -1

    I think the problem was "value = 'text/xml; charset=utf-8'." I changed it by "value = 'application/xml'." and I'am connected.

    But, now I have a different error message: "424 Failed Dependency". Is it also a problem SAP or something in the API?

    Thanks for your help.

    Fernando

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 14 at 02:00 PM
    -1

    It was a format problem of XML fichier.

    Closed.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 13 at 07:09 PM

    Parameter LENGTH in method SET_CDATA is optional and has default value -1 (automatic length determination).

    You send an empty request body with length = 0 in your code. This is interpreted from server as http error 415.

    CALL METHOD http_client->request->set_cdata
     EXPORTING
     data = wf_string
     offset = 0
     length = rlength.
    Add comment
    10|10000 characters needed characters exceeded