发布 http 接口,以供第三方系统调用
1.se24 创建一个类,并继承接口IF_HTTP_EXTENSION,
2.回车后重写方法HANDLE_REQUEST,并添加GET,POST方法(根据自己的需求来)
3.根据实际业务对POST方法进行代码写入
method post. ***json以及内表参数 data:it_fybx type table of zsfbt002_type01 , gt_return type table of zsfbt002_type02, gv_message type char1, json_fybx type string, gv_return type string, json_return type string. data: lv_content_type type string. data:all_num type p, "传入json参数的字符个数 json_num type p. "实际需要的参数个数 " Delivers the HTTP body of this entity as character data json_fybx = server->request->get_cdata( ). "获取入参json数据 if json_fybx is initial. server->response->set_status( code = 404 reason = '未解析到Body参数,请检查' ). return. endif. all_num = strlen( json_fybx ). json_num = all_num - 12. json_fybx = json_fybx+11(json_num). zcl_json=>deserialize( exporting json = json_fybx changing data = it_fybx ). "将Json转换成内表 if it_fybx is not initial. call function 'ZF_FBT_002' importing message = gv_message tables it_fybx = it_fybx it_return = gt_return. call method zcl_json=>serialize "返回参数 内表转JSON exporting data = gt_return pretty_name = 'U' receiving r_json = gv_return. concatenate '{"IT_RETURN":' gv_return '}' into json_return. if gv_message = 'S'. server->response->set_cdata( json_return ). server->response->set_status( code = 200 reason = 'OK' ). "Sets current HTTP status code lv_content_type = 'application/json'. server->response->set_content_type( lv_content_type ). else. server->response->set_cdata( json_return ). * server->response->set_status( code = 500 reason = 'ERROR' ). server->response->set_status( code = 200 reason = 'ERROR' ). endif. ELSE. server->response->set_status( code = 200 reason = 'Input Json Data Error' ). endif. endmethod.
4.GUI端配置
Tcode: SICF 配置服务
在登录数据中没有设置账号密码的话 ,链接后面可以直接添加,比如:
http://sapqas.xxxxx.com:8001/zfbt/zfbt001?sap-client=800&sap-user=账号&sap-password=密码
对应的端口号查看或者更改Tcode:SMICM
使用soapui或者postman工具就可以直接测试了。
如果需要发布含Token 验证的接口,可以参考链接:【SAP】SAP 发布HTTP接口之完整的Restful 含( 含Token 验证)_sap 获取token-CSDN博客
标签:set,return,type,server,json,fybx,HTTP,SAP,RESTful From: https://www.cnblogs.com/freeandeasy/p/17836496.html