Mule HTTP请求:错误查询参数与大字符串

I am calling the REST (PHP) from Mule HTTP Request using query-param.

This works fine, with small params data!

But one of the params ("rest_data") is a content file (Base64 encoded). When the file content is large (> ~8K) the request faild. I think that params does not support large strings.

What should be the way to use body instead query-param on Mule in this case?

See the configuration file:

   <http:request-config name="HTTP_Request_Configuration" host="164.164.164.233" port="80" basePath="/crmtec/service/v4_1/rest.php" doc:name="HTTP Request Configuration">
    </http:request-config>
    <http:request config-ref="HTTP_Request_Configuration" path="/" method="POST" doc:name="HTTP Documento">
        <http:request-builder>
            <http:query-param paramName="method" value="set_document_revisions"/>
            <http:query-param paramName="input_type" value="JSON"/>
            <http:query-param paramName="response_type" value="JSON"/>
            <http:query-param paramName="rest_data" value="#[flowVars.params.rest_data]"/>
        </http:request-builder>
        <http:success-status-code-validator values="0..599"/>
    </http:request>

Whatever is in the payload will be send in the body of the HTTP request, so you should add that rest_data to the payload with a set-payload component before the http:request component:

<set-payload value="#[flowVars.params.rest_data**]"/>

It's not a good practice to use query params for large data, that's why it fails.

I faced this similar issue while calling GIS REST API. Try below code. For post request, you can the payload as MAP of all params. Well designed REST should be able to handle it -

<set-payload value='#[{'method':'set_document_revisions', 'input_type':'JSON', 'response_type':'JSON','rest_data':flowVars.params.rest_data}]' />
<http:request config-ref="HTTP_Request_Configuration" path="/" method="POST" doc:name="HTTP Documento">
        <http:success-status-code-validator values="0..599"/>
    </http:request>

We should be using POST method instead of GET to send large data structures over HTTP

When you query parameters are long, you would think about put the query string into the HTTP request body, set the request type to POST method instead of GET.

Here is a page list the limit of how many characters in a URL: https://boutell.com/newfaq/misc/urllength.html

Remember that the query string (name/value pairs) get transformed in the URL of GET request

GET /something/?name1=value1&name2=value2 HTTP/1.1 Host: yourhost

POST /something/ HTTP/1.1 Host: yourhost name1=value1&name2=value2