When curl is used to send some data to the server without looking at the details, the following results may be obtained. this is not the ideal result:
- [Content_type] => multipart/form-data; boundary = ---------- f924413ea122
However, if you use http_build_query ($ post_data) to replace $ post_data and submit data to this php script, different results will be obtained. this is the ideal result:
- [Content_type] => application/x-www-form-urlencoded
As shown in the preceding example, when curl is used and the parameter is data, the http header will send content_type: application/x-www-form-urlencoded when you submit data to the server. This is a normal webpage The header sent by the browser when the form is submitted. While multipart/form-data knows that this is a form used to upload files. Contains boundary delimiters, which can contain many more bytes.
The full data to post in a http "post" operation. to post a file, prepend a filename with @ and use the full path. this can either be passed as a urlencoded string like 'para1 = val1? 2 = val2 &... 'Or as an array with the field name as key and field data as value. if value is an array, the content-type header will be set to multipart/form-data.
When using arrays to provide post data, the curl component is probably intended to be compatible with the writing method of the uploaded file such as @ filename. by default, content_type is set to multipart/form-data. Although it does not affect most servers, a small number of servers are not compatible.
Conclusion: If you do not need to upload files, perform http_build_query on the data submitted by post as much as possible, and then send it out to achieve better compatibility and smaller request packets. |