更改目的地的路径前缀
Change the path prefix of the destination
我有一个由某些程序自动创建的目的地。
现在我想在运行时以编程方式更改目标的路径前缀。这可能吗?
我正在阅读此文档
这里提到,如果没有提到路径前缀,那么可以更改 URI。所以我有一个没有路径前缀的目的地,然后我尝试使用方法“if_http_utility~set_request_uri”,但这也没有用。
附上代码示例
*&---------------------------------------------------------------------*
*& 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.
我不是 ABAP 和 ABAP HTTP 框架方面的专家。你能提供一些关于如何实现我的场景的提示吗?
此致,
索拉夫
试试这个:
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 ).
更改网址更方便。
要知道 HTTP 请求是否有效,您应该在收到后阅读响应:
call method client->receive
...
data(response) = client->response->get_cdata( ). " <== missing part
我认为 RFC 目标(事务 SM59)的 "path prefix" 在运行时不能被忽略,因为管理员所做的定制不应该被程序忽略。
(我没有任何正式的论证参考,我只是做了一个测试来证实你的发现)
这可以看成是操作系统的低级命令,管理员会在事务SM49中定义允许ABAP程序使用的命令,其他命令不能使用。
此外,RFC目标的其他数据可能只对该路径前缀有效(例如身份验证)。
如果应允许程序访问任何路径,则应要求管理员将路径前缀留空。
我有一个由某些程序自动创建的目的地。
现在我想在运行时以编程方式更改目标的路径前缀。这可能吗?
我正在阅读此文档
这里提到,如果没有提到路径前缀,那么可以更改 URI。所以我有一个没有路径前缀的目的地,然后我尝试使用方法“if_http_utility~set_request_uri”,但这也没有用。
附上代码示例
*&---------------------------------------------------------------------*
*& 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.
我不是 ABAP 和 ABAP HTTP 框架方面的专家。你能提供一些关于如何实现我的场景的提示吗?
此致,
索拉夫
试试这个:
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 ).
更改网址更方便。
要知道 HTTP 请求是否有效,您应该在收到后阅读响应:
call method client->receive
...
data(response) = client->response->get_cdata( ). " <== missing part
我认为 RFC 目标(事务 SM59)的 "path prefix" 在运行时不能被忽略,因为管理员所做的定制不应该被程序忽略。
(我没有任何正式的论证参考,我只是做了一个测试来证实你的发现)
这可以看成是操作系统的低级命令,管理员会在事务SM49中定义允许ABAP程序使用的命令,其他命令不能使用。
此外,RFC目标的其他数据可能只对该路径前缀有效(例如身份验证)。
如果应允许程序访问任何路径,则应要求管理员将路径前缀留空。