PHP卷曲获取请求返回错误

时间:2015-05-15 15:25:04

标签: php curl get

我正在做一些事情,但我不明白发生了什么。我尝试了不同的东西。我正在向网站发送获取请求,但它不起作用,卷曲总是返回false。但是,如果我把网址放到浏览器并检查它,我得到了一些回应。这是网址

"https://cleanlead.dlg.co.uk/?circuit=public&fuseaction=lead&Campid=599&Suppid=571&Surveyid=5&Title=Mr&Forename=Adrian&Surname=Reut&Address1=8 Church Road Middlesex&Finance_Insurance_PMI_CurrentlyHave=Yes&Postcode=UB3 2LH&Finance_PMI_ThruCompany=No&TelephoneORMobile=2087976760&Age_Band=30-39"

这是'我的卷曲代码

$ch = curl_init();  
//var_dump($url.$postData);
curl_setopt($ch,CURLOPT_URL,urlencode("https://cleanlead.dlg.co.uk/?circuit=public&fuseaction=lead&Campid=599&Suppid=571&Surveyid=5&Title=Mr&Forename=Adrian&Surname=Reut&Address1=8 Church Road Middlesex&Finance_Insurance_PMI_CurrentlyHave=Yes&Postcode=UB3 2LH&Finance_PMI_ThruCompany=No&TelephoneORMobile=2087976760&Age_Band=30-39"));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER, false); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);   
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); 
$output=curl_exec($ch);

curl_close($ch);
var_dump($output);

1 个答案:

答案 0 :(得分:1)

在这种情况下,您只需要urlencode()查询字符串的值部分,字段PostcodeAddress1

<?php

$ch = curl_init();  
//var_dump($url.$postData);
$requestUrl = "https://cleanlead.dlg.co.uk/?";
$requestUrl .= "circuit=public&fuseaction=lead&Campid=599&Suppid=571&Surveyid=5&Title=Mr&Forename=Adrian&Surname=Reut";
$requestUrl .= "&Address1=" . urlencode("8 Church Road Middlesex");
$requestUrl .= "&Finance_Insurance_PMI_CurrentlyHave=Yes";
$requestUrl .= "&Postcode=" . urlencode("UB3 2LH");
$requestUrl .= "&Finance_PMI_ThruCompany=No&TelephoneORMobile=2087976760&Age_Band=30-39";
curl_setopt($ch,CURLOPT_URL, $requestUrl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER, false); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);   
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); 
$output=curl_exec($ch);
if (curl_error($ch)) {
    var_dump();
}
curl_close($ch);
var_dump($output);


?>