on 10-21-2019 4:09 AM
Hello Experts,
I am totally new to sap , I am currently integrating solman 7.2 to servicenow using rfc (http to external server) using a listener on a specific port.
Through the listener us reachable , I am getting 400 bad request error when I configure the API in rfc (host name - Listener host, port and API path prefix ) .
The same rest API works from other test interfaces like ..postman and Powershell ise however it's failing here.
I have not been able to find the root cause for this.
Could you please guide me how to investigate further and what could be the possibilly be the reason for this issue.
Regards,
Sandeep
Hi Sandeep Pati,
If you want to consume a API, you can follow the below approach too. This approach directly consumes the URL instead of the RFC. Check if this works for your scenario.
DATA:
lo_http_client TYPE REF TO if_http_client,
lo_rest_client TYPE REF TO cl_rest_http_client,
lo_exp TYPE REF TO zcx_rest_misc_exp,
lo_response TYPE REF TO if_rest_entity,
lo_request TYPE REF TO if_rest_entity.
DATA:
lv_url TYPE string,
lv_data TYPE string,
lv_errcd TYPE i,
lv_response TYPE string.
lv_url = '<your url here>'.
lv_data = '<JSON data>'.
"Create request
cl_http_client=>create_by_url(
EXPORTING
url = lv_url
IMPORTING
client = lo_http_client " HTTP Client Abstraction
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4
).
"Set protocol
lo_http_client->request->set_version( if_http_request=>co_protocol_version_1_0 ).
"Create rest request
CREATE OBJECT lo_rest_client
EXPORTING
io_http_client = lo_http_client.
"Request request
lo_request = lo_rest_client->if_rest_client~create_request_entity( ).
lo_request->set_content_type( iv_media_type = if_rest_media_type=>gc_appl_json ).
lo_request->set_string_data( lv_data ).
lo_rest_client->if_rest_resource~post( io_entity = lo_request ).
lo_response = lo_rest_client->if_rest_client~get_response_entity( ).
lv_errcd = lo_response->get_header_field( iv_name = `~status_code` ).
lv_response = lo_response->get_string_data( ).
Thanks,
Gourab
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.