DATA lv_url TYPE string.
DATA lc_http_client TYPE REF TO if_http_client.
*1、安装规则拼接url
lv_url = '深圳'."如果url中有中文需要做需要做ASCII转码
CALL METHOD cl_http_utility=>escape_url
EXPORTING
unescaped = lv_url
RECEIVING
escaped = lv_url.
lv_url = 'http:
&& lv_url && '&key=网上申请的key'.
*2、创建客户端请求
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = lv_url
* proxy_host = 'proxy'"有的系统需要用代理
* proxy_service = '0000'
IMPORTING
client = lc_http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc NE 0.
*失败
ENDIF.
*3、按照对方的接口规则,设置传输参数
*"POST OR GET
*CALL METHOD lc_http_client->request->set_method( 'POST' ).
*"head
*CALL METHOD lc_http_client->request->set_header_field
* EXPORTING
* name = 'Content-Type'
* value = 'form-data'.
*"body
*CALL METHOD lc_http_client->request->set_form_field
* EXPORTING
* name = 'version'
* value = '2.0'.
*4、发送和接受
CALL METHOD lc_http_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
http_invalid_timeout = 4
OTHERS = 5.
IF sy-subrc NE 0.
*失败
ENDIF.
CALL METHOD lc_http_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4.
IF sy-subrc NE 0.
*失败
ENDIF.
DATA l_result_string TYPE string.
l_result_string = lc_http_client->response->get_cdata( ).