源代码:
*&---------------------------------------------------------------------*
*& Report ZYTEST
*&
*&---------------------------------------------------------------------*
*& ABAP与搜索引擎
*&
*&---------------------------------------------------------------------*
REPORTZYTEST.
PARAMETER:
P_QUERYTYPE CLENGTH30DEFAULT'SAP公司'.
DATA:
V_QUERYTYPESTRING.
DATA:
O_CONVOUTTYPE REF TOCL_ABAP_CONV_OUT_CE.
V_QUERY=P_QUERY.
O_CONVOUT=CL_ABAP_CONV_OUT_CE=>CREATE(ENCODING='8400').
O_CONVOUT->WRITE(DATA=V_QUERY).
DATAV_ENCODEDTYPEXSTRING.
CALL METHODCL_HTTP_UTILITY=>ENCODE_UTF8
EXPORTING
UNENCODED=V_QUERY
RECEIVING
ENCODED=V_ENCODED
EXCEPTIONS
CONVERSION_FAILED=1
OTHERS=2.
IFSY-SUBRC .
* Implement suitable error handling here
ENDIF.
DATA:V_ESCAPEDTYPESTRING.
CALL METHODCL_HTTP_UTILITY=>ESCAPE_URL
EXPORTING
UNESCAPED=V_QUERY
* OPTIONS =
RECEIVING
ESCAPED=V_ESCAPED.
CL_HTTP_CLIENT=>CREATE(
EXPORTING
HOST='www.baidu.com'
SERVICE=''
IMPORTING
CLIENT=DATA(O_CLIENT)
EXCEPTIONS
OTHERS=4).
IFSY-SUBRC .
RETURN.
ENDIF.
CL_HTTP_UTILITY=>SET_REQUEST_URI(
REQUEST=O_CLIENT->REQUEST
URI='/s?wd='&& V_ESCAPED).
CALL METHODCL_GUI_FRONTEND_SERVICES=>EXECUTE
EXPORTING
APPLICATION='C:\Program Files\Internet Explorer\iexplore.exe'"本地IE的安装位置
PARAMETER='http://www.baidu.com/s?wd='&& V_ESCAPED"网页URL
EXCEPTIONS
CNTL_ERROR=1
ERROR_NO_GUI=2
BAD_PARAMETER=3
FILE_NOT_FOUND=4
PATH_NOT_FOUND=5
FILE_EXTENSION_UNKNOWN=6
ERROR_EXECUTE_FAILED=7
SYNCHRONOUS_FAILED=8
NOT_SUPPORTED_BY_GUI=9
OTHERS=10.
O_CLIENT->CLOSE( ).
执行结果:
领取专属 10元无门槛券
私享最新 技术干货