*&---------------------------------------------------------------------*
*& Form FRM_SENT_FIELD
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> LV_FILE_XSTRING
*& <-- LV_OSS_ID
*&---------------------------------------------------------------------*
FORM FRM_SENT_FIELD USING P_LV_FILE_XSTRING
CHANGING P_LV_OSS_ID.
DATA:
lo_http_client TYPE REF TO IF_HTTP_CLIENT,
iv_url TYPE string.
DATA:
LV_FILE_XSTRING TYPE XSTRING,
LV_RESULT_STRING TYPE string,
LV_MESSAGE TYPE STRING,
LV_OSS_ID TYPE STRING,
lv_i TYPE I.
"sent data to cloud
DATA: L_URL TYPE STRING ,
L_PARAMS_STRING TYPE STRING ,
L_HTTP_CLIENT TYPE REF TO IF_HTTP_CLIENT ,
CLIENT TYPE REF TO IF_HTTP_CLIENT ,
L_RESULT TYPE STRING ,
L_STATUS_TEXT TYPE STRING ,
L_HTTP_STATUS_CODE TYPE I ,
L_HTTP_LENGTH TYPE I ,
L_PARAMS_XSTRING TYPE XSTRING ,
L_XSTRING TYPE XSTRING ,
L_IS_XML_TABLE TYPE STANDARD TABLE OF SMUM_XMLTB ,
L_IS_RETURN TYPE STANDARD TABLE OF BAPIRET2 ,
L_OUT_TAB TYPE STANDARD TABLE OF TBL1024,
PART TYPE REF TO IF_HTTP_ENTITY ,
IT_DATA1 TYPE STANDARD TABLE OF MARA,
IT_DATA TYPE XSTRING,
LV_LEN TYPE I.
DATA: IT_FILE_CONTENT_BINARY TYPE STANDARD TABLE OF SDOKCNTBIN,
PATH TYPE STRING VALUE '<PATH NAME>',
PATH1 TYPE STRING VALUE '<SUBPATH NAME>'.
iv_url = 'http://ehr-m.dev.qdama.cn:48888/ehrDownloadService/upload/ufs/batchUploadFile'.
"clear:LO_HTTP_CLIENT.
CALL METHOD CL_HTTP_CLIENT=>CREATE_BY_URL
EXPORTING
URL = IV_URL
IMPORTING
CLIENT = LO_HTTP_CLIENT
EXCEPTIONS
ARGUMENT_NOT_FOUND = 1
PLUGIN_NOT_ACTIVE = 2
INTERNAL_ERROR = 3.
CALL METHOD LO_HTTP_CLIENT->request->set_method( if_http_request=>co_request_method_post ).
CALL METHOD LO_HTTP_CLIENT->request->set_version( if_http_request=>co_protocol_version_1_0 ).
CALL METHOD LO_HTTP_CLIENT->request->if_http_entity~set_content_type(
EXPORTING
content_type = 'multipart/form-data' ).
CALL METHOD LO_HTTP_CLIENT->request->if_http_entity~set_formfield_encoding
EXPORTING
formfield_encoding = cl_http_request=>if_http_entity~co_encoding_raw.
part = LO_HTTP_CLIENT->request->if_http_entity~add_multipart( ).
CALL METHOD part->set_header_field
EXPORTING
name = 'content-disposition'
value = 'form-data; name="file"; filename="god.jpg";'.
CALL METHOD part->set_content_type
EXPORTING
content_type = 'application/x-jpg-compressed'.
LV_LEN = xstrlen( P_LV_FILE_XSTRING ).
CALL METHOD part->set_data
EXPORTING
data = P_LV_FILE_XSTRING
offset = 0
length = LV_LEN.
CALL METHOD LO_HTTP_CLIENT->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4.
"读取远程服务返回的处理过结果。
CALL METHOD LO_HTTP_CLIENT->RECEIVE
EXCEPTIONS
HTTP_COMMUNICATION_FAILURE = 1
HTTP_INVALID_STATE = 2
HTTP_PROCESSING_FAILED = 3.
IF SY-SUBRC <> 0 .
LO_HTTP_CLIENT->GET_LAST_ERROR( IMPORTING MESSAGE = LV_MESSAGE ).
* E_RETURN-MESSAGE = LV_MESSAGE.
* E_RETURN-TYPE = 'E'.
RETURN.
ELSE.
LV_RESULT_STRING = LO_HTTP_CLIENT->RESPONSE->GET_CDATA( ).
* E_DATA = /UI2/CL_JSON=>GENERATE( JSON = LV_RESULT_STRING ).
ENDIF.
ENDFORM.
http 发送文件
原创
©著作权归作者所有:来自51CTO博客作者wx60dd44933d0df的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Delphi实现http发送xml文件片段
默认有Idhttp组件,名称叫IdHttp1。服务端收到的汉字不是乱码。
delphi Post Xml