简体   繁体   English

CURLOPT_POSTFIELDS 编码

[英]CURLOPT_POSTFIELDS encoding

I'm not sure about what encoding to use when using cURL:我不确定使用 cURL 时使用什么编码:

GET:得到:

(URL=) http://www.example.com/form.php?test=test+1 (URL=) http://www.example.com/form.php?test=test+1

(URL=) http://www.example.com/form.php?test=test%201 (URL=) http://www.example.com/form.php?test=test%201

POST:邮政:

(POSTFIELDS=) test=test 1 (POSTFIELDS=) 测试=测试 1

(POSTFIELDS=) test=test+1 (POSTFIELDS=) 测试=测试+1

(POSTFIELDS=) test=test%201 (POSTFIELDS=) 测试=测试%201

CURL can accept an array of arguments for post, and it'll take care of the encoding for you: CURL 可以接受 arguments 的数组进行发布,它会为您处理编码:

$array = (
    'test' => 'test 1',
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $array);

However, as per the curl docs (http://php.net/curl_setopt, search for CURLOPT_POST_FIELDS), for PHP, the pairs should be in urlencode() format:但是,根据 curl 文档(http://php.net/curl_setopt,搜索 CURLOPT_POST_FIELDS),对于 PHP,这些对应为urlencode()格式:

$post_args = urlencode('test=test 1');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_args);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM