SAP调用RestfulApi接口接收数据

因为准备要做一个关于调用外部接口的需求,所以自己先练习一下。

程序说明:我已经在.net开发的系统里提供一个api接口,现在在sap访问这个接口,来接收数据。

这里涉及Restful Api知识,以后再分享。

这是一个api地址:http://10.X.X.X:8081/api/test/gettest

首先根据这个url创建一个http客户端

1call method cl_http_client=>create_by_url 2 exporting 3 url = url 4 importing 5 client = http_client 6 exceptions 7 argument_not_found = 1 8 plugin_not_active = 2 9 internal_error = 3 10 others = 4.

选择一个HTTP GET METHOD

http_client->request->set_method( if_http_request=>co_request_method_get ).

发送和接收数据

1"发送 2 call method http_client->send 3 exceptions 4 http_communication_failure = 1 5 http_invalid_state = 2 6 http_processing_failed = 3 7 http_invalid_timeout = 4 8 others = 5. 9 10 "接收 11 call method http_client->receive 12 exceptions 13 http_communication_failure = 1 14 http_invalid_state = 2 15 http_processing_failed = 3.   

最后就可以获取接收的数据了

1"获取接口返回的数据 2 result = http_client->response->get_cdata( ). 3 4 write: result.

输出结果是这样的

跟外部系统返回的数据是一致的。

附上完整代码

1data: len type i,"发送报文长度 2 len_string type string, 3 url type string, "接口地址 4 http_client type ref to if_http_client,"http客户端 5 post_string type string, 6 result type string. 7 8data: it_header type tihttpnvp. 9 10 11 12start-of-selection. 13 14 url = 'http://10.X.X.X:8081/api/test/gettest'. 15 16 17 "创建http客户端 18 call method cl_http_client=>create_by_url 19 exporting 20 url = url 21 importing 22 client = http_client 23 exceptions 24 argument_not_found = 1 25 plugin_not_active = 2 26 internal_error = 3 27 others = 4. 28 29 "设置http method 为Get 30 http_client->request->set_method( if_http_request=>co_request_method_get ). 31 32 "发送 33 call method http_client->send 34 exceptions 35 http_communication_failure = 1 36 http_invalid_state = 2 37 http_processing_failed = 3 38 http_invalid_timeout = 4 39 others = 5. 40 41 "接收 42 call method http_client->receive 43 exceptions 44 http_communication_failure = 1 45 http_invalid_state = 2 46 http_processing_failed = 3. 47 48 "获取接口返回的数据 49 result = http_client->response->get_cdata( ). 50 51 write: result.

以后会继续分享用POST方法发送数据到外部接口的例子。  

作者:明光烁亮
出处:http://www.cnblogs.com/hezhongxun/
微信号:HEme922 欢迎加好友一起交流SAP!
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

java将前端的json数组字符串转换为列表

记录下在前端通过ajax提交了一个json数组的字符串,在后端如何转换为列表。前端数据转化与请求varcontracts{id:'1',name:'yanggb合同1'},{id:'2',name:'yanggb合同2'},{id:'3',name:'yang