1. HTTP发送JSON格式数据:

  1. function zap_01_url_sap_to_c3 .
  2. *"----------------------------------------------------------------------
  3. *"*"本地接口:
  4. *" IMPORTING
  5. *" VALUE(I_FLAG) TYPE STRING OPTIONAL
  6. *" VALUE(I_TITLE) TYPE STRING
  7. *" VALUE(I_MESSAGE) TYPE STRING
  8. *" EXPORTING
  9. *" VALUE(E_RETURN) TYPE STRING
  10. *" TABLES
  11. *" IT_REVEIVER
  12. *"----------------------------------------------------------------------
  13.  
  14. data: lv_url type string."http 服务接口地址
  15. data: lo_http_client type ref to if_http_client.
  16. data: lv_respon type string.
  17. data: lv_subrc type sy-subrc.
  18. data: lv_json_str type string. "发送报文
  19. data: lv_msgty type c,
  20. lv_msgtx type string.
  21.  
  22. data: lt_json type standard table of zscma_dyjg,
  23. ls_json type zscma_dyjg.
  24.  
  25. * 设置报文内容
  26. ls_json-source = 'ERP' . "来源 订阅号的英文名
  27. ls_json-sender = 'ERP' . "发送者
  28. ls_json-sender_type = 'S' . "默认个人 P为个人 S为系统
  29.  
  30. data:lv_reveiver type string.
  31.  
  32. loop at it_reveiver.
  33. if sy-tabix eq .
  34. lv_reveiver = it_reveiver.
  35. else.
  36. lv_reveiver = lv_reveiver && ',' && it_reveiver.
  37. endif.
  38. endloop.
  39.  
  40. ls_json-title = i_title . "发送标题
  41. ls_json-content = i_message.
  42. ls_json-message = 'message'. "
  43. ls_json-channel = 'SUBSCRIPTION'. "
  44. ls_json-messagedata = i_message. "
  45.  
  46. if i_flag is initial.
  47.  
  48. concatenate 'http://XXX.XXX.XXX.XXX:XXXX/mc/core/message/sendMessageUnitForCode?source=' ls_json-source
  49. '&sender='ls_json-source'&sender_type=S&receiver='lv_reveiver'&title='ls_json-title
  50. '&content='ls_json-content'&message='ls_json-message
  51. '&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'
  52. into lv_url .
  53.  
  54. * /mc/core/message/sendMessageUnitForCode
  55. * /mc/core/message/sendMessageUnit
  56.  
  57. elseif i_flag eq 'X'.
  58. concatenate 'http://XXX.XXX.XXX.XXX:XXXX/mc/core/message/sendMessageUnitForCode?source=' ls_json-source
  59. '&sender='ls_json-source'&sender_type=S&receiver='lv_reveiver'&title='ls_json-title
  60. '&content='ls_json-content'&message='ls_json-message
  61. '&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'
  62. into lv_url .
  63. endif.
  64.  
  65. "创建客户端请求
  66. call method cl_http_client=>create_by_url
  67. exporting
  68. url = lv_url
  69. importing
  70. client = lo_http_client
  71. exceptions
  72. argument_not_found =
  73. plugin_not_active =
  74. internal_error =
  75. others = .
  76.  
  77. "设定传输请求内容格式以及编码格式
  78. lo_http_client->request->set_content_type( content_type = 'application/json; charset=utf-8' ).
  79.  
  80. "设定调用服务
  81. lo_http_client->request->set_method( if_http_request=>co_request_method_post ).
  82.  
  83. "发送请求
  84. lo_http_client->send( exceptions http_communication_failure =
  85. http_invalid_state = ).
  86.  
  87. "读取远程服务返回的处理过结果。
  88. lo_http_client->receive( exceptions http_communication_failure =
  89. http_invalid_state =
  90. http_processing_failed = ).
  91.  
  92. e_return = lo_http_client->response->get_cdata( ).
  93.  
  94. e_return = e_return+().
  95.  
  96. translate e_return to upper case.
  97.  
  98. endfunction.

2. 调用ODATA service,插入数据,事物码STRUST添加信任证书。

 HTTPS:

  1. CALL METHOD cl_http_client=>create
  2. EXPORTING
  3. host = 'api15.sapsf.cn'
  4. service = ''
  5. scheme = ''
  6. ssl_id = 'ANONYM'
  7. * proxy_host = wf_proxy
  8. * proxy_service = wf_port
  9. IMPORTING
  10. client = lo_http_client.
  11.  
  12. lo_http_client->propertytype_logon_popup = lo_http_client->co_disabled.
  13. CALL METHOD lo_http_client->authenticate(
  14. EXPORTING
  15. * client = '110'
  16. * proxy_authentication = 'X'
  17. username = ''
  18. password = ''
  19. * LANGUAGE = 'E'
  20. ).
  21. CALL METHOD lo_http_client->request->set_header_field
  22. EXPORTING
  23. name = '~request_protocol'
  24. value = 'HTTPS/1.0'.
  25. CALL METHOD lo_http_client->request->set_header_field
  26. EXPORTING
  27. name = '~request_uri'
  28. value = '/odata/v2/......'.
  29. CALL METHOD lo_http_client->request->set_header_field
  30. EXPORTING
  31. name = 'Content-Type'
  32. value = 'application/json; charset=utf-8'.
  33. CALL METHOD lo_http_client->request->set_method( 'POST' ).

ABAP-HTTP发送JSON的更多相关文章

  1. ABAP接口之Http发送json报文

    abap 调用http 发送 json 测试函数 SE11创建结构:zsmlscpnotice SE37创建函数:zqb_test_http_fuc1 FUNCTION zqb_test_http_f ...

  2. PHP如何通过Http Post请求发送Json对象数据?

    因项目的需要,PHP调用第三方 Java/.Net 写好的 Restful Api,其中有些接口,需要 在发送 POST 请求时,传入对象. Http中传输对象,最好的表现形式莫过于JSON字符串了, ...

  3. SpringMVC客户端发送json数据时报400错误

    当测试客户端发送json数据给服务器时,找不到响应路径? 原来是参数类型不符,即使是json也要考虑参数的个数和类型 解决:将age请求参数由"udf"改为"3" ...

  4. JMeter学习(三十五)使用jmeter来发送json/gzip格式数据

    一.使用jmeter来发送gzip数据 有时候我们需要模拟在客户端将数据压缩后, 发送(post)到服务器端. 通常这种情况,会发生在移动终端上. 这样做的好处, 是可以节省流量.  当然, 服务器返 ...

  5. java httpclient发送json 请求 ,go服务端接收

    /***java客户端发送http请求*/package com.xx.httptest; /** * Created by yq on 16/6/27. */ import java.io.IOEx ...

  6. iOS开发网络篇—发送json数据给服务器以及多值参数

    iOS开发网络篇—发送json数据给服务器以及多值参数 一.发送JSON数据给服务器 发送JSON数据给服务器的步骤: (1)一定要使用POST请求 (2)设置请求头 (3)设置JSON数据为请求体 ...

  7. 【转】iOS开发网络篇—发送json数据给服务器以及多值参数

    原文: http://www.cnblogs.com/wendingding/p/3950132.html 一.发送JSON数据给服务器 发送JSON数据给服务器的步骤: (1)一定要使用POST请求 ...

  8. Jmeter 发送json{Jfinal 接口req rsp均为json}

    链接地址:http://yangyoupeng-cn-fujitsu-com.iteye.com/blog/2013649 使用jmeter发送json数据.方法有三种 原创,转载请注明出处 1.利用 ...

  9. perl post发送json数据

    sub  wx_init {                #$login_url ="https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit?r=- ...

  10. 利用 CURL 发送JSON格式字符串

    /* * post 发送JSON 格式数据 * @param $url string URL * @param $data_string string 请求的具体内容 * @return array ...

随机推荐

  1. C# 使用oledb 方式连接本地或者远程oracel 数据库的方式

    对于C# 进行oracle 数据库的开发来说使用oracle 提供的odp.net 方式是比较方便的,同时在性能以及兼容性也是比较好的 但是,对于不打算使用的,那么该如何使用oledb 进行连接 连接 ...

  2. 在oracle的连接(join)中使用using关键字

    如果是使用natraul join,并且两张表中如果有多个字段是具有相同的名称和数据类型的,那么这些字段都将被oracle自作主张的将他们连接起来. 但实际上我们有时候是不需要这样来连接的.我们只需要 ...

  3. 网络基础 TCP/IP

    为了理解 HTTP,我们有必要事先了解一下 TCP/IP 协议族.通常使用的网络(包括互联网)是在 TCP/IP 协议族的基础上运作的.而 HTTP 属于它内部的一个子集.接下来,我们仅介绍理解 HT ...

  4. spring 使用 maven profile

    先看看 maven 定义 profile 的写法 <!-- profiles --> <profiles> <profile> <activation> ...

  5. centos6安装GitLab全程详解和常见问题解决

    GitLab,是一个使用 Ruby on Rails 开发的开源应用程序,与Github类似,能够浏览源代码,管理缺陷和注释,非常适合在团队内部使用. 官方只提供了Debian/Ubuntu系统下的安 ...

  6. JZ2440 裸机驱动 第13章 LCD控制器(2)

    13.2 TFT LCD显示实例 13.2.1 程序设计     本实例的目的是从串口输出一个菜单,从中选择各种方法进行测试,比如画线. 画圆.显示单色.使用调色板等. 13.2.2代码详解     ...

  7. 【python】python性能分析--待完善

    http://www.oschina.net/translate/python-performance-analysis http://blog.csdn.net/gzlaiyonghao/artic ...

  8. GNU C与ANSI C的不同

    引用:http://tsroad.lofter.com/post/376316_57ac519 1.GNU C可定义0长度数组,目的是为了定义可变长结构体. struct var_struct{    ...

  9. 关于 android 返回键 代码实现

    转自:http://www.dewen.io/q/11313/android+%E6%A8%A1%E6%8B%9F%E8%BF%94%E5%9B%9E%E9%94%AE%E5%8A%9F%E8%83% ...

  10. form 表单提交浏览器的enctype(编码方式)

    1. method 为 get 时 enctype :x-www-form-urlencoded(默认), 把form数据append到对应的url后面: 2. method 为 post 时 Bro ...