0

I'm trying to make a Curl request to an EndPoint. This request has a param which a string text. The function at the Endpoint only return the same string. The issue is that the Endpoint's function only return the first word of the String.

Here is the code I use:

$params = $_SESSION['search'].'/'.$_SESSION['page'];
$curl   = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER  => true,
    CURLOPT_USERAGENT       => 'Stlfinder',
    CURLOPT_POST            => false,
    CURLOPT_URL             => "mydomain.com/api/search/$params"
));
$resultados = curl_exec($curl);
curl_close($curl);
$resultados   = json_decode($resultados);
print_r($resultados);

This is what I get:

stdClass Object ( [result] => The )

and the String sent is: 'The mansion book'

Is there anything missing in the Curl?

2
  • Have you tried printing the value of $params? Commented Mar 11, 2016 at 1:07
  • I also notice that your question is about POST, but you have POST set to false and the string contains spaces but is not urlencoded. Commented Mar 11, 2016 at 1:14

1 Answer 1

3

Since your query string has spaces, it's getting chopped off at the first space. I think you need something like:

$params = rawurlencode($_SESSION['search'].'/'.$_SESSION['page']);

That will replace the spaces with %20 and will handle other non-alpha characters in other strings.

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

2 Comments

Well, I used your function and at the first time did not work. I made a little changes. $params = rawurlencode($_SESSION['search']).'/'.$_SESSION['page'];
Great. Glad it helped.

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.