*&---------------------------------------------------------------------*
*& Report ZAPI
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZAPI.
* Declaración de tipos.
TYPES: BEGIN OF ty_datos,
name1 LIKE lfa1-name1,
sortl LIKE lfa1-sortl,
land1 LIKE lfa1-land1,
spras LIKE lfa1-spras,
END OF ty_datos.
DATA : lo_http_client TYPE REF TO if_http_client.
DATA : l_str_length TYPE i.
DATA : mime TYPE w3mimetabtype.
DATA: l_datos TYPE ty_datos,
t_datos TYPE STANDARD TABLE OF ty_datos.
DATA gv_json_output TYPE string.
*SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-s01.
*PARAMETERS: p_inv TYPE belnr_d DEFAULT '12345'.
*SELECTION-SCREEN: END OF BLOCK b1.
START-OF-SELECTION.
*Data variables for storing response in xstring and string
DATA : lv_xstring TYPE xstring,
lv_string TYPE string,
lv_node_name TYPE string.
CLEAR : lv_xstring, lv_string, lv_node_name.
DATA : lv_cdata TYPE string.
DATA : lv_content_length_value TYPE i.
CLEAR : lv_cdata, lv_content_length_value.
*Pass the URL to get Data
CLEAR : lv_xstring, lv_string, lv_node_name.
lv_string = 'https://openapi.naver.com/v1/papago/n2mt?source=ko&target=en&text=안녕.'.
*Creation of New IF_lo_http_client Object
cl_http_client=>create_by_url(
EXPORTING
url = lv_string
IMPORTING
client = lo_http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
).
IF sy-subrc IS NOT INITIAL.
* Handle errors
ENDIF.
lo_http_client->propertytype_logon_popup = lo_http_client->co_disabled.
* lo_http_client->request->set_method( 'POST' ).
CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = '~request_method'
value = 'POST'.
* CALL METHOD lo_http_client->request->set_header_field
* EXPORTING
* name = 'content-type:'
* value = 'application/x-www-form-urlencoded'.
CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = 'Content-Type:'
value = 'application/x-www-form-urlencoded;charset=UTF-8'.
CALL METHOD lo_http_client->request->set_header_field "We pass header and value
EXPORTING
name = 'X-Naver-Client-Id:'
value = 'Rh6y2FN_54MoIYIXHdDq'.
CALL METHOD lo_http_client->request->set_header_field "We pass header and value
EXPORTING
name = 'X-Naver-Client-Secret:'
value = 'Q4GcM0CQmV'.
*
* CALL METHOD lo_http_client->request->set_form_field
* EXPORTING
* name = 'grant_type'
* value = 'password'.
* CALL METHOD lo_http_client->request->set_form_field
* EXPORTING
* name = 'username'
* value = 'admin'.
* CALL METHOD lo_http_client->request->set_form_field
* EXPORTING
* name = 'password'
* value = 'abc123'.
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
OTHERS = 4.
IF sy-subrc NE 0.
DATA subrc TYPE sysubrc.
DATA errortext TYPE string.
CALL METHOD lo_http_client->get_last_error
IMPORTING
code = subrc
message = errortext.
WRITE: / 'communication_error( receive )',
/ 'code: ', subrc, 'message: ', errortext.
EXIT.
ELSE.
****Get the response content in Character format
* content = client->response->get_cdata( ).
ENDIF.
** lo_client->receive( ).
** IF sy-subrc IS NOT INITIAL.
*** Handle errors
** ENDIF.
END-OF-SELECTION.
**Return the HTTP body of this entity as binary data
*lv_xstring = lo_http_client->response->get_data( ).
*Return the HTTP body of this entity as string data
DATA(lv_string2) = lo_http_client->response->get_cdata( ).
* BREAK-POINT.
/ui2/cl_json=>deserialize(
EXPORTING json = lv_string2
pretty_name = /ui2/cl_json=>pretty_mode-camel_case
CHANGING data = t_datos ).
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
671 | 직원 데이터 [1] | sapjoy | 2024.07.02 | 241 |
670 | REPORT Z99_24. | sapjoy | 2024.05.21 | 83 |
669 | REPORT Z06_01. | sapjoy | 2024.04.21 | 60 |
668 | REPORT z05_36 | sapjoy | 2023.02.08 | 270 |
» | API | sapjoy | 2022.11.03 | 351 |
666 | z15_21_drag | sapjoy | 2022.02.24 | 307 |
665 | Z18_06_DRAGCLASS | sapjoy | 2022.02.23 | 334 |
664 | REPORT Z21_01 | sapjoy | 2015.10.28 | 2276 |
663 | subroutine pool | sapjoy | 2013.11.16 | 3314 |
662 | REPORT Z20_01. | sapjoy | 2012.08.02 | 5097 |
661 | REPORT Z19_02. | sapjoy | 2012.08.02 | 3953 |
660 | REPORT z19_01. | sapjoy | 2012.08.02 | 3559 |
659 | REPORT z18_06. | sapjoy | 2012.08.02 | 3195 |
658 | REPORT z18_05 | sapjoy | 2012.08.02 | 3384 |
657 | REPORT z18_04 . | sapjoy | 2012.08.02 | 3388 |
656 | REPORT z18_03. | sapjoy | 2012.08.02 | 4598 |
655 | REPORT z18_02. | sapjoy | 2012.08.02 | 3124 |
654 | REPORT z18_01. | sapjoy | 2012.08.02 | 3152 |
653 | REPORT z17_23 | sapjoy | 2012.08.02 | 2538 |
652 | REPORT z17_22 | sapjoy | 2012.08.02 | 2307 |