日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

SAP 与 JSON 接口实施案例一

發布時間:2025/3/20 javascript 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SAP 与 JSON 接口实施案例一 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
  • 接口背景
  • Request 無參數
  • Receive是純數據
  • ?

  • 變量定義
  • DATA: lo_client TYPE REF TO if_http_client,

    lo_request TYPE REF TO if_http_request,

    lv_result TYPE string,

    lv_errocode TYPE sysubrc,

    lv_message TYPE string,

    lv_input TYPE string,

    lv_xinput TYPE xstring.

    DATA:

    lr_json_reader TYPE REF TO if_sxml_reader.

    DATA: lv_url TYPE string.

    ?

    TYPES: BEGIN OF lty_keywords,

    key TYPE string,

    deleted_at TYPE string,

    translations TYPE ty_trans,

    END OF lty_keywords.

    ?

    DATA: lt_result TYPE TABLE OF lty_keywords.

  • 調用JSON request
  • lv_url = 'http://xx.xxx.0.217/api/keywords'.

    CALL METHOD cl_http_client=>create_by_url

    EXPORTING

    url = lv_url

    IMPORTING

    client = lo_client

    EXCEPTIONS

    argument_not_found = 1

    plugin_not_active = 2

    internal_error = 3

    OTHERS = 4.

    ?

    IF sy-subrc IS NOT INITIAL.

    " Error

    EXIT.

    ENDIF.

    ?

    lo_client->request->set_header_field( EXPORTING name = '~request_method' value = 'GET' ).

    ?

    lo_client->authenticate(

    EXPORTING

    * proxy_authentication = 'X'

    username = 'certipedia'

    password = 'jfds8201'

    * language =

    ).

    ?

    CALL METHOD lo_client->send

    EXCEPTIONS

    http_communication_failure = 1

    http_invalid_state = 2

    http_processing_failed = 3

    http_invalid_timeout = 4

    OTHERS = 5.

    IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    ENDIF.

    ?

    ?

    ?

    ?

    ?

  • 接受返回值
  • CALL METHOD lo_client->receive

    EXCEPTIONS

    http_communication_failure = 1

    http_invalid_state = 2

    http_processing_failed = 3

    OTHERS = 4.

    ?

    CALL METHOD lo_client->get_last_error

    IMPORTING

    code = lv_errocode

    message = lv_message.

    ?

    lv_input = lo_client->response->get_cdata( ).

    ?

  • 返回數據格式轉換
  • CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

    EXPORTING

    text = lv_input

    IMPORTING

    buffer = lv_xinput

    EXCEPTIONS

    failed = 1???

    OTHERS = 2.

    IF sy-subrc <> 0.

    * Implement suitable error handling here

    ENDIF.

    ?

    lr_json_reader = cl_sxml_string_reader=>create( input = lv_xinput ).

    ?

    CALL TRANSFORMATION id SOURCE XML lr_json_reader

    RESULT keywords = lt_result.

    ?

    lo_client->close( ).

    總結

    以上是生活随笔為你收集整理的SAP 与 JSON 接口实施案例一的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。