我通过CL_HTTP_CLIENT
使用JSON的POST请求。面临以下情况:
当xstrlen(jsonx)<= 1024时,得到http_rc = 200
(OK)。
当xstrlen(jsonx)> 1024时,我得到http_rc = 400
(给出的数据不正确)。
配置文件参数icm/HTTP/max_request_size_KB = 102400
。
尝试不通过SAP客户端发送相同的数据,结果为200(正常)。
而不是client->request->set_data
我用client->request->set_сdata
,结果是类似的,只要字符串大小超过1024字节,我得到一个400响应。
可能是什么错误,我在某种程度上填写的数据不正确?
请求数据是否有大小限制?
代码:
DATA: client TYPE REF TO if_http_client.
cl_http_client=>create_by_destination( EXPORTING
destination = 'z_test'
IMPORTING
client = client ).
client->propertytype_logon_popup = if_http_client=>co_disabled.
client->request->set_version( if_http_request=>co_protocol_version_1_1 ).
client->request->set_method( if_http_request=>co_request_method_post ).
client->request->set_header_field( name = 'Accept' value = 'application/json' ).
client->request->set_header_field( name = 'Content-Type' value = 'application/json' ).
client->request->set_header_field( name = 'Authorization' value = |Bearer TokenValue| ).
DATA: json TYPE string.
DATA: jsonx TYPE xstring.
json = '{"data":['.
json = json && '{"login":"login1","first_name":"first_name","last_name":"last_name","email":"[email protected]","status":"active","invited":true,"change_password":false,'.
json = json && '"groups":[{"path":"path"}]},'.
json = json && '{"login":"login2","first_name":"first_name","last_name":"last_name","email":"[email protected]","status":"active","invited":true,"change_password":false,'.
json = json && '"groups":[{"path":"path"}]},'.
* json = json && '{"login":"login3","first_name":"first_name","last_name":"last_name","email":"[email protected]","status":"active","invited":true,"change_password":false,'.
* json = json && '"groups":[{"path":"path"}]},'.
json = json && '{"login":"login4","first_name":"first_name","last_name":"last_name","email":"[email protected]","status":"active","invited":true,"change_password":false,'.
json = json && '"groups":[{"path":"path"}]},'.
json = json && '{"login":"login5","first_name":"first_name","last_name":"last_name","email":"[email protected]","status":"active","invited":true,"change_password":false,'.
json = json && '"groups":[{"path":"path"}]},'.
json = json && '{"login":"login7","first_name":"first_name","last_name":"last_name","email":"[email protected]","status":"active","invited":true,"change_password":false,'.
json = json && '"groups":[{"path":"path"}]}],'.
json = json && '"partial_sync":false,"chief_sync":false,"notify_users":false,"with_whitelist":false}'.
jsonx = cl_abap_codepage=>convert_to(
source = json
codepage = 'UTF-8' ).
DATA(json_lenx) = xstrlen( jsonx ).
client->request->set_data( data = jsonx
offset = 0
length = json_lenx ).
* DATA(get_jsonx) = client->request->get_cdata( ).
CALL METHOD client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
http_invalid_timeout = 4
OTHERS = 5.
IF sy-subrc <> 0.
RAISE connection_error.
ENDIF.
CALL METHOD client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4.
IF sy-subrc = 0.
DATA: http_rc TYPE sy-subrc.
client->response->get_status( IMPORTING code = http_rc ).
l_xml = client->response->get_cdata( ).
ENDIF.
client->close( ).
字符串
1条答案
按热度按时间sqserrrh1#
问题出在SM59设置上。压缩的连接设置必须为非活动。如果压缩非活动,则不会出现错误。
的数据