ABAP http_client执行http请求
来源:互联网 发布:海岛奇兵医疗升级数据 编辑:程序博客网 时间:2024/06/07 14:53
本人现在正在做银企互联接口,由于银行前置机程序只支持SOCKET连接,所以现在在用JAVA开发了一个中间件,但是在ABAP中构建XML文件发送到中间件时,如果碰到奇数个中文汉字则最后一个汉字会变成乱码,而对于偶数汉字则没有任何问题。。。
附ABAP代码和JAVA代码:
ABAP构建XML文件:
call function 'SDIXML_DATA_TO_DOM'
exporting
name = objname
dataobject = dataobj
importing
data_as_dom = dom
changing
document = document
exceptions
others = 01.
if sy-subrc = 0.
call method document->append_child
exporting
new_child = dom
receiving
rval = rc.
if rc = 0.
* convert DOM to XML
call function 'SDIXML_DOM_TO_XML'
exporting
document = document
* pretty_print = 'X'
importing
xml_as_string = xml_as_string
tables
xml_as_table = xml_as_table
exceptions
others = 1.
call function 'HR_KR_XSTRING_TO_STRING'
exporting
* from_codepage = '8400'
from_codepage = '4110'
in_xstring = xml_as_string
importing
out_string = xmlstring "XML文件串
exceptions
others = 1.
endif.
endif.
发送文件:
l_len = strlen( xmlstring ) .
cl_http_client=>create_by_url(
exporting url = url
importing client = http_client ).
call method http_client->request->set_header_field
exporting
name = 'Content-Type'
value = 'text/xml; charset=utf-8'.
call method http_client->request->set_header_field
exporting
name = '~request_method'
value = 'POST'.
call method http_client->request->set_cdata
exporting
data = xmlstring
offset = 0
length = l_len.
call method http_client->send
exceptions
http_communication_failure = 1
http_invalid_state = 2.
if sy-subrc <> 0.
rc = sy-subrc.
return.
endif.
call method http_client->receive
exceptions
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3.
if sy-subrc <> 0.
rc = sy-subrc.
return.
endif.
JAVA端接受时的处理:
message = new String(message.getBytes(), "UTF-8");
message = new String(message.getBytes(), "GB2312");
Debug.printLog("Request:" + message);
message为SAP过来的字符串,经转换后就会出现上面的状况。
诚心求解!! 本人现在正在做银企互联接口,由于银行前置机程序只支持SOCKET连接,所以现在在用JAVA开发了一个中间件,但是在ABAP中构建XML文件发送到中间件时,如果碰到奇数个中文汉字则最后一个汉字会变成乱码,而对于偶数汉字则没有任何问题。。。
附ABAP代码和JAVA代码:
ABAP构建XML文件:
call function 'SDIXML_DATA_TO_DOM'
exporting
name = objname
dataobject = dataobj
importing
data_as_dom = dom
changing
document = document
exceptions
others = 01.
if sy-subrc = 0.
call method document->append_child
exporting
new_child = dom
receiving
rval = rc.
if rc = 0.
* convert DOM to XML
call function 'SDIXML_DOM_TO_XML'
exporting
document = document
* pretty_print = 'X'
importing
xml_as_string = xml_as_string
tables
xml_as_table = xml_as_table
exceptions
others = 1.
call function 'HR_KR_XSTRING_TO_STRING'
exporting
* from_codepage = '8400'
from_codepage = '4110'
in_xstring = xml_as_string
importing
out_string = xmlstring "XML文件串
exceptions
others = 1.
endif.
endif.
发送文件:
l_len = strlen( xmlstring ) .
cl_http_client=>create_by_url(
exporting url = url
importing client = http_client ).
call method http_client->request->set_header_field
exporting
name = 'Content-Type'
value = 'text/xml; charset=utf-8'.
call method http_client->request->set_header_field
exporting
name = '~request_method'
value = 'POST'.
call method http_client->request->set_cdata
exporting
data = xmlstring
offset = 0
length = l_len.
call method http_client->send
exceptions
http_communication_failure = 1
http_invalid_state = 2.
if sy-subrc <> 0.
rc = sy-subrc.
return.
endif.
call method http_client->receive
exceptions
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3.
if sy-subrc <> 0.
rc = sy-subrc.
return.
endif.
JAVA端接受时的处理:
message = new String(message.getBytes(), "UTF-8");
message = new String(message.getBytes(), "GB2312");
Debug.printLog("Request:" + message);
message为SAP过来的字符串,经转换后就会出现上面的状况。
诚心求解!!
- ABAP http_client执行http请求
- 使用AsyncTask执行HTTP请求
- LotusScript代码执行Http请求
- linux下执行http请求
- java执行http请求乱码解决
- Zend_Http_Client 执行http请求 --(手册)
- Liberty nova-api HTTP请求执行流程
- boost执行http的GET请求
- Nginx重试引发Http请求重复执行
- Gauge中执行Http请求测试
- 解决angularjs中同步执行http请求
- OkHttp3 HTTP请求执行流程分析
- linux发送http请求不执行原因 请求头
- No module named http_client
- ABAP修改请求号
- sap abap执行命令
- Android网络框架之Http请求的分发与执行
- http页面执行https跨协议请求的解决办法
- Questions for C++
- HttpServlet
- 实验 构造函数
- 开始→运行→输入的命令集锦
- WINCE有感
- ABAP http_client执行http请求
- 安装完apache 应做的20件事情
- HttpServletRequest和HttpServletResponse(1)
- Apache 实现禁止图片盗链
- VC pragma指令
- maps.google 和ditu.google
- PHP实现文件下载
- 虽然年轻,但要敢于设计
- 八大排序算法