Reputation: 5936
I have a destination created automatically by some program.
Now I want to change the path prefix of the destination programmatically during runtime. Is this possible ?
I was going through this documentation
This mentions that if the path prefix is not mentioned then the URI can be changed. So I had a destination without path prefix and then I tried using method "if_http_utility~set_request_uri", but this also did not work.
Code sample attached
*&---------------------------------------------------------------------*
*& Report http_destination_program
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT http_destination_program.
DATA client type ref to if_http_client.
DATA cl_http_util type ref to cl_http_utility.
DATA dest type rfcdest.
DATA gv_subrc TYPE sysubrc.
DATA uri type string.
DATA timeout type I.
DATA errortext type string.
uri = '/do/b/json'.
DEST = 'SAP'.
errortext = ' Cannot connect to server'.
timeout = 0.
CALL METHOD cl_http_client=>create_by_destination
exporting destination = dest
importing client = client
exceptions
others = 6.
cl_http_utility=>set_request_uri( request = client->request uri = uri ).
gv_subrc = cl_http_utility=>get_last_error( ).
IF gv_subrc <> 0.
WRITE: / 'Wrong URI format'.
EXIT.
ENDIF.
write 'Hello Saurav'.
call method client->send
exporting timeout = timeout
exceptions others = 4.
if sy-subrc <> 0.
call method client->get_last_error
importing code = gv_subrc
message = errortext.
write: / 'communication_error( send )',
/ 'code: ', gv_subrc, 'message: ', 'test'.
endif.
call method client->receive
exceptions others = 4.
if sy-subrc <> 0.
call method client->get_last_error
importing code = gv_subrc
message = errortext.
write: / 'communication_error( receive )',
/ 'code: ', gv_subrc, 'message: ', 'test'.
endif.
I am not an expert in ABAP and ABAP HTTP framework . Can you please provide some hints on how can I achieve my scenario ?
Best Regards,
Saurav
Upvotes: 1
Views: 7156
Reputation: 13656
I think that the "path prefix" of the RFC destination (transaction SM59) can't be ignored at runtime, because the customizing done by an administrator shouldn't be ignored by programs.
(I don't have any official reference for argumenting, I only did a test to confirm your finding)
This can be seen like low-level commands of the operating system, an administrator will define the ones allowed to be used by ABAP programs in transaction SM49, the other commands can't be used.
Moreover, the other data of the RFC destination may only be valid for this path prefix (authentication for instance).
If a program should be allowed to access any path, then the administrator should be asked to leave the path prefix empty.
Upvotes: 1
Reputation: 13656
To know whether the HTTP request works, you should read the response after receiving :
call method client->receive
...
data(response) = client->response->get_cdata( ). " <== missing part
Upvotes: 1
Reputation: 5091
Try this one instead:
cl_http_client=>create_by_url(
EXPORTING
url = lv_url
IMPORTING
client = DATA(lo_http_client)
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4 ).
It's more convenient for changing URLs.
Upvotes: 0