【轉載】CL_HTTP_CLIENT的HTTP和SOAP用法示例
***SOAP方式呼叫WebService
REPORT z_barry_http_soap_post LINE-SIZE 1023.
DATA: http_client TYPE REF TO if_http_client .
DATA: proxy_host TYPE string VALUE '10.99.60.203' ,
proxy_port TYPE string VALUE '8080',
proxy_user TYPE string ,
proxy_pass TYPE string .
DATA: len TYPE i,
len_str TYPE string .
DATA: post_string TYPE string ,
return_str TYPE string .
PARAMETERS: p_code(11) TYPE c OBLIGATORY DEFAULT '1381852'.
PARAMETERS: p_user(20) TYPE c .
START-OF-SELECTION .
CONCATENATE ''
'http://www.w3.org/2001/XMLSchema-instance"'
' xmlns:xsd="http://www.w3.org/2001/XMLSchema"'
' xmlns:soap="'">http://schemas.xmlsoap.org/soap/envelope/">'
''
''">http://WebXml.com.cn/">'
'' p_code ''
'' p_user ''
''
''
''
INTO post_string .
len = STRLEN( post_string ) .
len_str = len .
CALL METHOD cl_http_client=>create
EXPORTING
host = 'webservice.webxml.com.cn'
service = '80'
scheme = '1'
* proxy_host = proxy_host
* proxy_service = proxy_port
IMPORTING
client = http_client.
http_client->propertytype_logon_popup = http_client->co_disabled.
* CALL METHOD http_client->authenticate
* EXPORTING
* proxy_authentication = 'X'
* username = proxy_user
* password = proxy_pass.
CALL METHOD http_client->request->set_header_field
EXPORTING
name = '~request_method'
value = 'POST'.
CALL METHOD http_client->request->set_header_field
EXPORTING
name = '~server_protocol'
value = 'HTTP/1.1'.
CALL METHOD http_client->request->set_header_field
EXPORTING
name = '~request_uri'
value = '/WebServices/MobileCodeWS.asmx'.
CALL METHOD http_client->request->set_header_field
EXPORTING
name = 'Content-Type'
value = 'text/xml; charset=utf-8'.
CALL METHOD http_client->request->set_header_field
EXPORTING
name = 'Content-Length'
value = len_str.
CALL METHOD http_client->request->set_header_field
EXPORTING
name = 'SOAPAction'
value = 'http://WebXml.com.cn/getMobileCodeInfo'.
CALL METHOD http_client->request->set_cdata
EXPORTING
data = post_string
offset = 0
length = 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.
CLEAR return_str .
return_str = http_client->response->get_cdata( ).
DATA : xstr TYPE xstring ,
str TYPE string ,
bin_tab TYPE STANDARD TABLE OF x255 ,
bin_len TYPE i.
xstr = http_client->response->get_data( ).
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = xstr
IMPORTING
output_length = bin_len
TABLES
binary_tab = bin_tab.
CALL FUNCTION 'SCMS_BINARY_TO_STRING'
EXPORTING
input_length = bin_len
mimetype = '"text/html; charset=utf-8"'
IMPORTING
text_buffer = str
TABLES
binary_tab = bin_tab.
CALL METHOD http_client->close.
WRITE return_str .
WRITE / str.
***HTTP POST 方法
REPORT z_barry_http_post LINE-SIZE 1023.
DATA: http_client TYPE REF TO if_http_client .
DATA: proxy_host TYPE string VALUE '10.99.60.203' ,
proxy_port TYPE string VALUE '8080',
proxy_user TYPE string ,
proxy_pass TYPE string .
DATA: len TYPE i,
len_str TYPE string .
DATA: post_string TYPE string ,
return_str TYPE string .
PARAMETERS: p_code(11) TYPE c OBLIGATORY DEFAULT '1381852'.
PARAMETERS: p_user(20) TYPE c .
START-OF-SELECTION .
CONCATENATE 'mobileCode=' p_code '&userID=' p_user INTO post_string.
len = STRLEN( post_string ) .
len_str = len .
CALL METHOD cl_http_client=>create
EXPORTING
host = 'webservice.webxml.com.cn'
service = '80'
scheme = '1'
proxy_host = proxy_host
proxy_service = proxy_port
IMPORTING
client = http_client.
http_client->propertytype_logon_popup = http_client->co_enabled .
* CALL METHOD http_client->authenticate
* EXPORTING
* proxy_authentication = 'X'
* username = proxy_user
* password = proxy_pass.
CALL METHOD http_client->request->set_header_field
EXPORTING
name = '~request_method'
value = 'POST'.
CALL METHOD http_client->request->set_header_field
EXPORTING
name = '~server_protocol'
value = 'HTTP/1.1'.
CALL METHOD http_client->request->set_header_field
EXPORTING
name = '~request_uri'
value = '/WebServices/MobileCodeWS.asmx/getMobileCodeInfo'.
CALL METHOD http_client->request->set_header_field
EXPORTING
name = 'Content-Type'
value = 'application/x-www-form-urlencoded'.
CALL METHOD http_client->request->set_header_field
EXPORTING
name = 'Content-Length'
value = len_str.
CALL METHOD http_client->request->set_cdata
EXPORTING
data = post_string
offset = 0
length = 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.
return_str = http_client->response->get_cdata( ).
CALL METHOD http_client->close.
WRITE return_str.
相關文章
- 轉載golang中net/http包用法GolangHTTP
- @Async的用法和示例
- 瞭解下SOAP HTTP 協議HTTP協議
- [轉載] Python中協程的詳細用法和例子Python
- 轉載:UML類圖中箭頭和線條的含義和用法
- 關於 SAP ABAP CL_HTTP_CLIENT API 中的 SSL_ID 引數HTTPclientAPI
- Sanic response stream() 函式用法和示例函式
- Sanic response redirect() 函式用法和示例函式
- Sanic response raw() 函式用法和示例函式
- Sanic response file() 函式用法和示例函式
- Sanic response json() 函式用法和示例JSON函式
- Sanic response html() 函式用法和示例HTML函式
- Sanic response text() 函式用法和示例函式
- [轉載] Oracle:start with...connect by子句的用法Oracle
- Python的HTTP庫及示例PythonHTTP
- 分割槽函式partition by的基本用法【轉載】函式
- Sanic response file_stream() 函式用法和示例函式
- 做了反向代理和負載均衡的nginx配置檔案簡單示例(nginx.conf) HTTP負載均衡/TCP負載均衡負載NginxHTTPTCP
- 5 分鐘學會 Git 常見用法和核心策略 (轉載)Git
- webservice快速入門-SOAP和WSDL(三)Web
- [轉載] Python日曆模組| 使用示例的weekday()方法Python
- Demo示例——Bundle打包和載入
- Http介面呼叫示例教程HTTP
- [轉載]PrintDocument,PrintDialog與PrintPreviewDialog用法總結View
- SQL中的case when then else end用法 【詳細】轉載SQL
- Sass @at-root 指令用法示例
- compare用法示例•選項摘要
- cdMysql?using?用法示例詳解MySql
- Rewrite %{HTTP_HOST}用法HTTP
- Linux 命令列:find 的 26 個用法示例Linux命令列
- 騰訊雲上 Selenium 用法示例
- python @pytest.fixture示例及用法Python
- [轉載]HTTP四種常見的POST提交資料方式HTTP
- Vue3.4+版本中的 defineModel 宏的用法示例Vue
- Rewrite %{HTTP_USER_AGENT}用法HTTP
- mpegts.js播放http/ts示例JSHTTP
- 一篇讀懂http-proxy-middleware(轉載)HTTP
- 【轉】ng-class的用法