DATA: http_client TYPE REF TO if_http_client.
"URL填全部,带参数
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = 'https://www.baidu.com'
IMPORTING
client = http_client.
http_client->propertytype_logon_popup = http_client->co_enabled .
http_client->propertytype_redirect = http_client->co_disabled .
CALL METHOD http_client->request->set_header_field
EXPORTING
name = '~request_method'
value = 'GET'.
CALL METHOD http_client->request->set_header_field
EXPORTING
name = '~request_protocol' "http请求则改为'~service_protocol'
value = 'HTTPS/1.1'. "'HTTP/1.1'
CALL METHOD http_client->request->set_header_field
EXPORTING
name = 'Content-Type'
value = 'text/html'. " text/html 看情况填application/json
* "set body
* CALL METHOD HTTP_CLIENT->REQUEST->SET_CDATA
* EXPORTING
* DATA = LV_PARAM
* OFFSET = 0
* LENGTH = LV_LEN.
CALL METHOD http_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2.
CALL METHOD http_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3.
* 获取返回的数据
DATA: r_value TYPE string,
r_value1 TYPE string,
r_fields TYPE tihttpnvp,
r_h_fields TYPE tihttpnvp.
http_client->response->get_header_fields( CHANGING fields = r_h_fields ).
注意:
1.url必须带"http://"或者“https://”。
2. http_client->propertytype_redirect = http_client->co_disabled .这一行是设置是否允许重定向,是为“co_enabled”,否为“co_disabled”。
3. 可能出现的错误 404 Hostname Unknow,是因为服务器未配置该url的dns
4. 可能出现的错误 401 refused,可能是被防火墙挡住了,以上两个问题可以找basis协助解决文章来源地址https://www.toymoban.com/news/detail-723198.html
文章来源:https://www.toymoban.com/news/detail-723198.html
到了这里,关于SAP ABAP调用Http/Https方式实例的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!