Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ABAP CL_HTTP_CLIENT REST - PUT method

0 Likes
5,484

Hi Experts,

I am able to do GET/POST methods with CL_HTTP_CLIENT,but while i am trying to PUT method it's getting error says "Method Not Allowed" HTTP-405.

CALL METHOD cl_http_client=>create_by_url

  EXPORTING

    url                = lv_url

  IMPORTING

    client             = lo_client

  EXCEPTIONS

    argument_not_found = 1

    plugin_not_active  = 2

    internal_error     = 3

    OTHERS             = 4.

IF sy-subrc NE 0.

*    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

*      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4

*     INTO cv_error_msg.

*    cv_error_occurred = 'X'.

*    RETURN.

ENDIF.

lo_client->authenticate(

   username = 'xxx'

   password = 'xxx'

).

*

CALL METHOD lo_client->request->set_header_field

  EXPORTING

    name  = '~request_method'

    value = 'PUT'.

"lo_client->request->set_method( 'PUT' ).

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

  EXPORTING

    text   = iv_json_data

  IMPORTING

    buffer = l_params_xstring

  EXCEPTIONS

    failed = 1

    OTHERS = 2.

lo_client->request->set_data( l_params_xstring ).

lo_client->request->set_content_type( 'application/json' ).

CALL METHOD lo_client->send

  EXCEPTIONS

    http_communication_failure = 1

    http_invalid_state         = 2

    http_processing_failed     = 3

    OTHERS                     = 4.

IF sy-subrc = 0.

ENDIF.

CALL METHOD lo_client->receive

  EXCEPTIONS

    http_communication_failure = 1

    http_invalid_state         = 2

    http_processing_failed     = 3.

CALL METHOD lo_client->response->get_status

  IMPORTING

    code   = l_http_status_code

    reason = l_status_text.

Let me know what i have missed in the above

Thanks,

Syam

1 ACCEPTED SOLUTION
Read only

Sandra_Rossi
Active Contributor
0 Likes
2,769

I guess the error is not from your side, but from the server (PUT not allowed by the server). You should better ask the admin or search internet.

6 REPLIES 6
Read only

Sandra_Rossi
Active Contributor
0 Likes
2,770

I guess the error is not from your side, but from the server (PUT not allowed by the server). You should better ask the admin or search internet.

Read only

0 Likes
2,769

Hi Sandra,

Thanks for quick response.

But ,while testing from the Postman of the URL with PUT method is allowing the server and make the updates the data as a sending through payload.

Thanks,

Syam

Read only

0 Likes
2,769

Did you trace and compare the two HTTP messages to identify where they are different? (Fiddler, etc.)

Read only

0 Likes
2,769

Good to know the problem is solved. Could you tell us what the problem was, and how you solved it? Thanks!

Read only

0 Likes
2,769

Hi Sandra,

Ya sure..

Because I am not passing the Key value to the URL.

Thanks,

Syam

Read only

0 Likes
2,769

Hi Syambabu,

Please let me know if how did you fix this

Thanks