Skip to Content
0
Jan 28, 2020 at 11:49 AM

REST API - method POST - Error 405 Method not allowed

1708 Views

Hello all,

when i try to call method POST I get error 405 Method not allowed. I have another method POST and this one work fine (but it is for get data). My method called by POST is for create card with data in WWW portal. When i put data from my method POST to the Postman everything is work fine.

IF mo_http_client IS BOUND AND mo_rest_client IS BOUND.
lv_url = 'https://rejestr-bdo.mos.gov.pl/api/WasteRegister/WasteTransferCard/v1/Kpo/create/plannedcard'.
cl_http_utility=>set_request_uri(
EXPORTING
request = mo_http_client->request " HTTP Framework (iHTTP) HTTP Request
uri = lv_url " URI String (in the Form of /path?query-string)
).
ENDIF.

* passing the Accept value in header which is a mandatory field
CALL METHOD mo_http_client->request->set_header_field
EXPORTING
name = 'Authorization'
value = |Bearer | && lv_token.

lv_body = zcl_json=>serialize(
data = ls_plannedcard
pretty_name = zcl_json=>pretty_mode-camel_case
mapping_fields = lt_mapping_fields ).

* Set Payload or body ( JSON or XML)
mo_request = mo_rest_client->if_rest_client~create_request_entity( ).
mo_request->set_content_type( iv_media_type = if_rest_media_type=>gc_appl_json ).

CALL METHOD mo_http_client->request->set_method EXPORTING method = 'POST'.

CALL METHOD mo_http_client->request->set_version EXPORTING version = if_http_request=>co_protocol_version_1_0. " 1.0

mo_request->set_string_data( lv_body ).

* POST
mo_rest_client->if_rest_resource~post( mo_request ).

* Collect response
mo_response = mo_rest_client->if_rest_client~get_response_entity( ).

* HTTP return status
mv_status_http = mv_status = mo_response->get_header_field( '~status_code' ).
mv_reason = mo_response->get_header_field( '~status_reason' ).
mv_content_length = mo_response->get_header_field( 'content-length' ).
mv_location = mo_response->get_header_field( 'location' ).
mv_content_type = mo_response->get_header_field( 'content-type' ).

* HTTP JSON return string
mv_response = mo_response->get_string_data( ).