0

I've to invoke this url in my Ubuntu 15.10 ...

http://listeps.cittadellasalute.to.it/?id=01090101

using curl both from command line and from PHP.

I've notice that no parameters are considered if I simply submit

curl 'http://listeps.cittadellasalute.to.it/?id=01090101'

You can note that no number appears in the result, exactly the same behaviour that you've if submit

curl 'http://listeps.cittadellasalute.to.it/'

The same using this PHP code

<?php
    ini_set('display_errors', 1);

    $url = 'http://listeps.cittadellasalute.to.it/?id=01090101';


    //#Set CURL parameters: pay attention to the PROXY config !!!!
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_PROXY, '');
    $data = curl_exec($ch);
    curl_close($ch);

    $dom = new DOMDocument();
    @$dom->loadHTML($data);

    $xpath = new DOMXPath($dom);

    $greenWaitingNumber = $xpath->query('/html/body/div/div/div[4]/div[3]/section/p');


    foreach( $greenWaitingNumber as $node )
    {
      echo "Number first green line: " .$node->nodeValue;
      echo '<br>';
      echo '<br>';
    }


?>

How may I using the url parameter both using curl from command line and in my PHP code?

3
  • 1
    What about using postman to get the right command? you can import your PHP code and then export to command line Commented Aug 11, 2017 at 21:57
  • do you have any sample? I don't know postman ... :-( Commented Aug 11, 2017 at 22:00
  • Did you tried reinstalling curl on ubuntu sudo apt-get install curl Commented Aug 11, 2017 at 22:33

2 Answers 2

1

The site makes an AJAX request

You didn't mess anything up. The html is empty at first, then it loads code.js, which makes a request to gtotal.php with the id. You can see all this if you open up the network tab in chrome dev tools.

To get the data:

curl http://listeps.cittadellasalute.to.it/gtotal.php?id=01090101

The parameters are sent, but the javascript part never runs.

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

Comments

1

Exporting from postman would result on something like this

curl -X GET 'http://listeps.cittadellasalute.to.it/?id=01090101'

you also can check this tutorial https://www.getpostman.com/docs/postman/sending_api_requests/generate_code_snippets

4 Comments

I've tried curl -X GET \ 'http://listeps.cittadellasalute.to.it/?id=01090101' but it doesn't work ... curl: (1) Protocol " http" not supported or disabled in libcurl .. trying curl -X GET "http://listeps.cittadellasalute.to.it/?id=01090101" I obtain the same behaviour as before ...
what's the response?
did you try this solution? askubuntu.com/questions/821186/…
Ok, I've just updated main response, apparently we have to use -XPUT

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.