我通过
CL_HTTP_CLIENT
使用带有 JSON 的 POST 请求。
遇到以下情况:
当 xstrlen( jsonx ) <= 1024, I get
http_rc = 200
(确定)。
当 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( ).