我使用curl从website1向website2提交一些数据.
当我通过接收端提交数据时,我得到它
Array
(
[ip] => 112.196.17.54
[amp;email] => test@test.com
[amp;user] => test123,
[amp;type] => point
[amp;password] => password
)
Run Code Online (Sandbox Code Playgroud)
根据我的http_build_query()产生错误的结果.
curl函数如下:http_build_query($ config)
function registerOnPoints($username ,$password,$email,$ip , $time )
{
$ch = curl_init("http://website2c.com/curl-handler");
curl_setopt(
$ch, CURLOPT_RETURNTRANSFER, 1);
$config = array( 'ip' => $ip,
'user' => $username,
'email' => $email,
'password'=> $password,
'time' => $time,
'type' => 'point') ;
# add curl post data
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($config));
curl_setopt($ch, CURLOPT_POST, true);
# execute
$response = curl_exec($ch);
# retreive status code
$http_status = curl_getinfo($ch , CURLINFO_HTTP_CODE);
if($http_status == '200')
{
$response = json_decode($response);
} else {
echo $http_status;
}
// Close handle
curl_close($ch);
}
Run Code Online (Sandbox Code Playgroud)
如果它是php版本问题那么,说清楚地说我没有权限更改php的版本因为只有curl函数产生错误休息项目完成并按预期工作.请帮我.
我想你可以试试:
http_build_query($config, '', '&');
Run Code Online (Sandbox Code Playgroud)
或替代方案:
$paramsArr = array();
foreach($config as $param => $value) {
$paramsArr[] = "$param=$value";
}
$joined = implode('&', $paramsArr);
//and use
curl_setopt($ch, CURLOPT_POSTFIELDS, $joined);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3302 次 |
| 最近记录: |