ABAP-HTTP发送JSON
1. HTTP发送JSON格式数据:
function zap_01_url_sap_to_c3 .
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" VALUE(I_FLAG) TYPE STRING OPTIONAL
*" VALUE(I_TITLE) TYPE STRING
*" VALUE(I_MESSAGE) TYPE STRING
*" EXPORTING
*" VALUE(E_RETURN) TYPE STRING
*" TABLES
*" IT_REVEIVER
*"---------------------------------------------------------------------- data: lv_url type string."http 服务接口地址
data: lo_http_client type ref to if_http_client.
data: lv_respon type string.
data: lv_subrc type sy-subrc.
data: lv_json_str type string. "发送报文
data: lv_msgty type c,
lv_msgtx type string. data: lt_json type standard table of zscma_dyjg,
ls_json type zscma_dyjg. * 设置报文内容
ls_json-source = 'ERP' . "来源 订阅号的英文名
ls_json-sender = 'ERP' . "发送者
ls_json-sender_type = 'S' . "默认个人 P为个人 S为系统 data:lv_reveiver type string. loop at it_reveiver.
if sy-tabix eq .
lv_reveiver = it_reveiver.
else.
lv_reveiver = lv_reveiver && ',' && it_reveiver.
endif.
endloop. ls_json-title = i_title . "发送标题
ls_json-content = i_message.
ls_json-message = 'message'. "
ls_json-channel = 'SUBSCRIPTION'. "
ls_json-messagedata = i_message. " if i_flag is initial. concatenate 'http://XXX.XXX.XXX.XXX:XXXX/mc/core/message/sendMessageUnitForCode?source=' ls_json-source
'&sender='ls_json-source'&sender_type=S&receiver='lv_reveiver'&title='ls_json-title
'&content='ls_json-content'&message='ls_json-message
'&channel=SUBSCRIPTION&messageData=%7B%22type%22%3A%2210002%22%2C%22createTime%22%3A%22%22%2C%22remarkUrl%22%3A%22http%3A%2F%2Fwww.baidu.com%22%7D'
into lv_url . * /mc/core/message/sendMessageUnitForCode
* /mc/core/message/sendMessageUnit elseif i_flag eq 'X'.
concatenate 'http://XXX.XXX.XXX.XXX:XXXX/mc/core/message/sendMessageUnitForCode?source=' ls_json-source
'&sender='ls_json-source'&sender_type=S&receiver='lv_reveiver'&title='ls_json-title
'&content='ls_json-content'&message='ls_json-message
'&channel=SUBSCRIPTION&messageData=%7B%22type%22%3A%2210002%22%2C%22createTime%22%3A%22%22%2C%22remarkUrl%22%3A%22http%3A%2F%2Fwww.baidu.com%22%7D'
into lv_url .
endif. "创建客户端请求
call method cl_http_client=>create_by_url
exporting
url = lv_url
importing
client = lo_http_client
exceptions
argument_not_found =
plugin_not_active =
internal_error =
others = . "设定传输请求内容格式以及编码格式
lo_http_client->request->set_content_type( content_type = 'application/json; charset=utf-8' ). "设定调用服务
lo_http_client->request->set_method( if_http_request=>co_request_method_post ). "发送请求
lo_http_client->send( exceptions http_communication_failure =
http_invalid_state = ). "读取远程服务返回的处理过结果。
lo_http_client->receive( exceptions http_communication_failure =
http_invalid_state =
http_processing_failed = ). e_return = lo_http_client->response->get_cdata( ). e_return = e_return+(). translate e_return to upper case. endfunction.
2. 调用ODATA service,插入数据,事物码STRUST添加信任证书。
HTTPS:
CALL METHOD cl_http_client=>create
EXPORTING
host = 'api15.sapsf.cn'
service = ''
scheme = ''
ssl_id = 'ANONYM'
* proxy_host = wf_proxy
* proxy_service = wf_port
IMPORTING
client = lo_http_client. lo_http_client->propertytype_logon_popup = lo_http_client->co_disabled.
CALL METHOD lo_http_client->authenticate(
EXPORTING
* client = '110'
* proxy_authentication = 'X'
username = ''
password = ''
* LANGUAGE = 'E'
).
CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = '~request_protocol'
value = 'HTTPS/1.0'.
CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = '~request_uri'
value = '/odata/v2/......'.
CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = 'Content-Type'
value = 'application/json; charset=utf-8'.
CALL METHOD lo_http_client->request->set_method( 'POST' ).
ABAP-HTTP发送JSON的更多相关文章
- ABAP接口之Http发送json报文
abap 调用http 发送 json 测试函数 SE11创建结构:zsmlscpnotice SE37创建函数:zqb_test_http_fuc1 FUNCTION zqb_test_http_f ...
- PHP如何通过Http Post请求发送Json对象数据?
因项目的需要,PHP调用第三方 Java/.Net 写好的 Restful Api,其中有些接口,需要 在发送 POST 请求时,传入对象. Http中传输对象,最好的表现形式莫过于JSON字符串了, ...
- SpringMVC客户端发送json数据时报400错误
当测试客户端发送json数据给服务器时,找不到响应路径? 原来是参数类型不符,即使是json也要考虑参数的个数和类型 解决:将age请求参数由"udf"改为"3" ...
- JMeter学习(三十五)使用jmeter来发送json/gzip格式数据
一.使用jmeter来发送gzip数据 有时候我们需要模拟在客户端将数据压缩后, 发送(post)到服务器端. 通常这种情况,会发生在移动终端上. 这样做的好处, 是可以节省流量. 当然, 服务器返 ...
- java httpclient发送json 请求 ,go服务端接收
/***java客户端发送http请求*/package com.xx.httptest; /** * Created by yq on 16/6/27. */ import java.io.IOEx ...
- iOS开发网络篇—发送json数据给服务器以及多值参数
iOS开发网络篇—发送json数据给服务器以及多值参数 一.发送JSON数据给服务器 发送JSON数据给服务器的步骤: (1)一定要使用POST请求 (2)设置请求头 (3)设置JSON数据为请求体 ...
- 【转】iOS开发网络篇—发送json数据给服务器以及多值参数
原文: http://www.cnblogs.com/wendingding/p/3950132.html 一.发送JSON数据给服务器 发送JSON数据给服务器的步骤: (1)一定要使用POST请求 ...
- Jmeter 发送json{Jfinal 接口req rsp均为json}
链接地址:http://yangyoupeng-cn-fujitsu-com.iteye.com/blog/2013649 使用jmeter发送json数据.方法有三种 原创,转载请注明出处 1.利用 ...
- perl post发送json数据
sub wx_init { #$login_url ="https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit?r=- ...
- 利用 CURL 发送JSON格式字符串
/* * post 发送JSON 格式数据 * @param $url string URL * @param $data_string string 请求的具体内容 * @return array ...
随机推荐
- log4net保存到数据库系列二:独立配置文件中配置log4net
园子里面有很多关于log4net保存到数据库的帖子,但是要动手操作还是比较不易,从头开始学习log4net数据库日志一.WebConfig中配置log4net 一.WebConfig中配置log4ne ...
- PHP经典乱码“口”字与解决办法
这几天看了看 Ajax 的基础知识,在练习一个简单的 请求和响应时,PHP 返回来的数据 在 IE 中开头总显示 一个 “锘” 字!上网 Baidu 了一下,发现这是由于 系统 处理 UTF-8 的方 ...
- zz 史上最全--各银行借记卡的年费、小额管理费、转账费等!
史上最全--各银行借记卡的年费.小额管理费.转账费等! 发布时间:2015-01-14 17:28:10 还在迷茫借记卡自费的菜主儿们~菜菜特别整理关于各银行借记卡.存折账户等的年费.小额管理费.转账 ...
- 【转】每天一个linux命令(22):find 命令的参数详解
原文网址:http://www.cnblogs.com/peida/archive/2012/11/16/2773289.html find一些常用参数的一些常用实例和一些具体用法和注意事项. 1.使 ...
- hadoop之 Yarn 调度器Scheduler详解
概述 集群资源是非常有限的,在多用户.多任务环境下,需要有一个协调者,来保证在有限资源或业务约束下有序调度任务,YARN资源调度器就是这个协调者. YARN调度器有多种实现,自带的调度器为Capaci ...
- bzoj 3611(洛谷 4103) [Heoi2014]大工程——虚树
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3611 https://www.luogu.org/problemnew/show/P4103 ...
- Django 博客项目02 Form验证+ 上传头像(预览)+Ajax用户注册
头像预览 $("#avatar_file").change(function(){ // 获取上传的文件对象 var file=$(this)[0].files[0]; // 读取 ...
- C++ 常用函数方法
/* * 拆分字符串 * 参数: * strData 字符串 * split 分隔符 * 返回: * 返回动态数组std::vector<std::string> ,记得要delete 内 ...
- 判断真实ip
#region 获取真实ip /// <summary> /// 获取真实ip /// </summary> ...
- 操作系统-移动操作系统-百科: iOS(苹果公司的移动操作系统)
ylbtech-操作系统-移动操作系统-百科: iOS(苹果公司的移动操作系统) iOS是由苹果公司开发的移动操作系统.苹果公司最早于2007年1月9日的Macworld大会上公布这个系统,最初是设计 ...