首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更改目标的路径前缀

更改目标的路径前缀
EN

Stack Overflow用户
提问于 2018-11-12 13:38:46
回答 3查看 4.3K关注 0票数 1

我有一个由某个程序自动创建的目的地。

现在,我希望在运行时以编程方式更改目标的路径前缀。这有可能吗?

我在看这些文件

cache=true

这提到,如果没有提到路径前缀,则可以更改URI。因此,我有一个没有路径前缀的目的地,然后尝试使用"if_http_utility~set_request_uri“方法,但这也不起作用。

附码样本

代码语言:javascript
复制
*&---------------------------------------------------------------------*
*& 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框架方面的专家。请您提供一些提示,说明我如何实现我的方案?

诚挚的问候,

索拉夫

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2018-11-12 17:01:42

要知道HTTP请求是否有效,您应该在接收到以下消息后读取响应:

代码语言:javascript
复制
call method client->receive
...
data(response) = client->response->get_cdata( ). " <== missing part
票数 1
EN

Stack Overflow用户

发布于 2018-11-13 10:20:53

我认为在运行时不能忽略RFC目的地(事务SM59)的“路径前缀”,因为程序不应该忽略管理员进行的自定义。

(我没有任何正式的论证参考资料,我只是做了一个测试来证实你的发现)

这可以看作是操作系统的低级命令,管理员将定义事务SM49中的ABAP程序允许使用的命令,其他命令不能使用。

此外,RFC目的地的其他数据可能仅对此路径前缀有效(例如,身份验证)。

如果应该允许程序访问任何路径,则应该要求管理员将路径前缀保留为空。

票数 1
EN

Stack Overflow用户

发布于 2018-11-12 15:50:13

试一试这个:

代码语言:javascript
复制
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 ).

更改URL更方便。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53263399

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档