我使用CURL在URL上提交表单,但没有得到任何响应,也没有收到任何卷曲错误。
使用以下参数:
$param
变量包含数组$accept
变量包含值" application/vnd.citrix.g2wapi-v1.1+json
" $contentType
包含值" application/json
"
<?php
function httpPost($url,$params,$accept,$contentType)
{
try{
$post_data=http_build_query($params);
//print_r($post_data);
// Initiate curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $post_data);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept:".$accept,
"Content-Type:".$contentType
));
// Execute
$result=curl_exec($ch);
if ($result==false)
{
print_r('Curl error: ' . curl_error($result));
}
// Closing
curl_close($ch);
// Will dump a beauty json :3
var_dump(json_decode($result, true));
} // end try
catch(Exception $e){
echo $e->getMessage();
return $e->getMessage();
}
} // end httpPost
?>