SAP-與-JSON的接口實(shí)施1_第1頁(yè)
SAP-與-JSON的接口實(shí)施1_第2頁(yè)
SAP-與-JSON的接口實(shí)施1_第3頁(yè)
SAP-與-JSON的接口實(shí)施1_第4頁(yè)
SAP-與-JSON的接口實(shí)施1_第5頁(yè)
已閱讀5頁(yè),還剩5頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、SAP 與 JSON 的接口 STYLEREF Document Control Information * MERGEFORMAT 文檔控制信息 DATE yyyy-MM-dd 2016-02-22第 SAP BDC 與 JSON的接口SAP 與 JSON 接口的實(shí)現(xiàn)方式SAP Search help簡(jiǎn)介與實(shí)現(xiàn) STYLEREF Document Identification * MERGEFORMAT Error! No text of specified style in document.目錄 DATE yyyy-MM-dd 2016-02-22第 Error! No text of

2、specified style in document.文檔介紹 本文檔旨在介紹SAP 與 JSON 接口的實(shí)現(xiàn)方式。什么是JSON有一種叫做JSON (JavaScript Object Notation) 的輕量級(jí)數(shù)據(jù)交換格式能夠替代XML的工作. 優(yōu)點(diǎn): 1. 數(shù)據(jù)格式比較簡(jiǎn)單, 易于讀寫(xiě), 格式都是壓縮的, 占用帶寬小 2. 易于解析這種語(yǔ)言, 客戶端JavaScript可以簡(jiǎn)單的通過(guò)eval()進(jìn)行JSON數(shù)據(jù)的讀取 3. 支持多種語(yǔ)言。JSON的一般調(diào)用Step1: Send the requestSend a JSON request via GET to Certipedia

3、to the relevant API end point, e.g.: HYPERLINK http:/xx.xx.0.216/api/keywords http:/xx.xx.0.216/api/keywords Note 1:The request has to be authorized via Basic access authentication See HYPERLINK /wiki/Basic_access_authentication /wiki/Basic_access_authentication.Note 2:The data are alwaysreturned JS

4、ON-encoded in the HTTP responsestructured as an Array of Hashes See HYPERLINK /wiki/Associative_array /wiki/Associative_arrayStep 2: Receive and interpret the responseExample HTTP response in which single keyword is received: key: yield-tested, deleted_at: null, translations: en: name: Yield Tested

5、, de: name: Ergiebigkeit geprft , pl: name: Przebadana wydajno Note: 可以在IE中直接輸入JSON request的地址,能夠看到返回結(jié)果。SAP 與 JSON 接口實(shí)施案例一 接口背景Request 無(wú)參數(shù)Receive是純數(shù)據(jù)變量定義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 st

6、ring,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.調(diào)用JSON requestlv_url

7、= http:/xx.xxx.0.217/api/keywords.CALL METHOD cl_http_client=create_by_urlEXPORTINGurl = lv_url IMPORTINGclient = lo_clientEXCEPTIONSargument_not_found = 1plugin_not_active = 2internal_error = 3OTHERS = 4.IF sy-subrc IS NOT INITIAL. ErrorEXIT.ENDIF.lo_client-request-set_header_field( EXPORTING name

8、= request_method value = GET ).lo_client-authenticate(EXPORTING* proxy_authentication = Xusername = certipediapassword = jfds8201* language =).CALL METHOD lo_client-sendEXCEPTIONShttp_communication_failure = 1http_invalid_state = 2http_processing_failed = 3http_invalid_timeout = 4OTHERS = 5.IF sy-su

9、brc 0.MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.ENDIF.接受返回值CALL METHOD lo_client-receiveEXCEPTIONShttp_communication_failure = 1http_invalid_state = 2http_processing_failed = 3OTHERS = 4.CALL METHOD lo_client-get_last_errorIMPORTINGcode = lv_errocodeme

10、ssage = lv_message.lv_input = lo_client-response-get_cdata( ).返回?cái)?shù)據(jù)格式轉(zhuǎn)換CALL FUNCTION SCMS_STRING_TO_XSTRINGEXPORTINGtext = lv_inputIMPORTINGbuffer = lv_xinputEXCEPTIONSfailed = 1OTHERS = 2.IF sy-subrc 0.* Implement suitable error handling hereENDIF.lr_json_reader = cl_sxml_string_reader=create( input

11、 = lv_xinput ).CALL TRANSFORMATION id SOURCE XML lr_json_readerRESULT keywords = lt_result.lo_client-close( ).SAP 與 JSON 接口實(shí)施案例二接口背景Request 有傳入?yún)?shù)Receive是返回一個(gè)jpg的URL數(shù)據(jù)定義 DATA: lo_client TYPE REF TO if_http_client, lo_request TYPE REF TO if_http_request, lv_parameter TYPE string, lv_parameter2 TYPE st

12、ring. DATA: lv_result TYPE string, lv_errocode TYPE sysubrc, lv_message TYPE string. DATA: ls_config TYPE zwzert_id_inf, lv_username TYPE string, lv_psw TYPE string, lv_url TYPE string.處理參數(shù) lv_parameter = & id: =ID=, & caption: =TMC=, & layout: 3, & keywords: =KEYWORD=, & qr_code_url: null, & third_

13、party_mark: null, & annual_ring_range: null, & annual_ring_text: null,. lv_parameter2 = output_format: 1, & output_quality: 1,* & generate_zip: true, & generate_zip: false, & use_small_font: =FONT=, & langs: & =LANG=, & =LANG=, & =LANG=* & & , & generate_jpg_instead_png:true& . lv_length = strlen( l

14、v_parameter ). CALL FUNCTION CONVERT_STRING_TO_TABLE EXPORTING i_string = lv_parameter i_tabline_length = 80 TABLES et_table = lt_table.發(fā)送JSON request 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

15、internal_error = 3 OTHERS = 4. lo_client-request-set_header_field( EXPORTING name = request_method value = POST ). lo_client-request-set_header_field( EXPORTING name = request_protocol value = HTTP/1.0 ). lo_client-request-set_header_field( EXPORTING name = Content-Type value = text/xml ). CALL METH

16、OD lo_client-request-set_header_field EXPORTING name = request_uri value = /generator/tdcgenerator.svc/generator. lo_client-request-set_cdata( EXPORTING data = lv_parameter offset = 0 length = lv_length ).CALL METHOD lo_client-authenticate EXPORTING* proxy_authentication = X* client = username = lv_

17、username password = lv_psw* 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. l

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論