0

I'm working on something but I do not understand what is happening. I tried different things. I'm sending a get request to website but it's not working, the curl always returns false. But if I put the url to the browser and check it, I got some response. here's the url

"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"

Here' my curl code

$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);
5
  • Don't urlencode the entire URL, only the applicable values. Commented May 15, 2015 at 15:31
  • So I will remove urlencode? Commented May 15, 2015 at 15:32
  • HTTP Error 400. The request is badly formed If i remove url encode Commented May 15, 2015 at 15:32
  • That isn't exactly what I said... read the manual on urlencode()... Commented May 15, 2015 at 15:32
  • put this after the $output line. if ($output === false) curl_error($ch); Commented May 15, 2015 at 15:35

1 Answer 1

1

You need to urlencode() only the value parts of your query string, fields Postcode and Address1 in this case.

<?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);


?>
Sign up to request clarification or add additional context in comments.

1 Comment

Wow. Thank you so much. This works for me. I just edited the parameters and make it an array instead. I hope I can select the others as answers as well. Thank u

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.