PHP Post请求返回'错误'。为什么?

时间:2016-12-05 10:44:54

标签: php post

我的php POST请求脚本总是返回错误,我不知道为什么。 我尝试了不同的方法,仍然没有运气。 当我尝试这个时,它会返回 找不到 抱歉,我们无法在该网址找到该网页。'

为什么?该网址有100%的页面

这是代码

$params = array(
    'apiKey' =>'*********',
    'titleID' => $title,
    'forename' => $yname,
    'surname' => $surname,
    'dayPhone' => $phone,
    'eveningPhone' => $phone_evening,
    'mobilePhone' => $phone_mobile,
     'email' => $email,
     'buyingBedrooms' => $bedroom_num,
     'buyingMinPrice' => $min_budget,
     'buyingMaxPrice' => $max_budget,
     'buyingNotes' => $message,
     'buyingActive' => true
    );

function httpPost($url,$params)
{
$postData = '';
 foreach($params as $k => $v) 
 { 
  $postData .= $k . '='.$v.'&'; 
 }
 $postData = rtrim($postData, '&');

 $ch = curl_init();  

curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_POST, count($postData));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);    

$output=curl_exec($ch);

if($output === false)
{
    echo "Error Number:".curl_errno($ch)."<br>";
    echo "Error String:".curl_error($ch);
}

curl_close($ch);
return $output;

}
echo httpPost("http://daisylets.domus.net/site/go/api/saveRegistration",$params);

任何帮助表示感谢。

1 个答案:

答案 0 :(得分:0)

尝试对网址进行编码

$postUrl = urlencode("http://daisylets.domus.net/site/go/api/saveRegistration");
echo httpPost($postUrl,$params);