CURLOPT_POSTFIELDS 编码

Sim*_*mon 1 php encoding curl

我不确定在使用 cURL 时要使用什么编码:

得到:

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

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

 

邮政:

(POSTFIELDS=) 测试=测试 1

(POSTFIELDS=) 测试=测试+1

(POSTFIELDS=) 测试=测试%201

Mar*_*c B 5

CURL 可以接受 post 的参数数组,它会为您处理编码:

$array = (
    'test' => 'test 1',
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $array);
Run Code Online (Sandbox Code Playgroud)

但是,根据 curl 文档(http://php.net/curl_setopt,搜索 CURLOPT_POST_FIELDS),对于 PHP,这些对应该采用以下urlencode()格式:

$post_args = urlencode('test=test 1');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_args);
Run Code Online (Sandbox Code Playgroud)