Hi,
I was trying to use cURL to do GET / POST request from a PHP in PAMP. I read somewhere that the library was included and it seems to be.
However I can't get it to work properly, I have the following function:
When trying for exampleCode:function get_web_page( $url ){ $options = array( CURLOPT_RETURNTRANSFER => true, // return web page CURLOPT_HEADER => false, // don't return headers CURLOPT_FOLLOWLOCATION => true, // follow redirects CURLOPT_ENCODING => "", // handle all encodings CURLOPT_USERAGENT => "spider", // who am i CURLOPT_AUTOREFERER => true, // set referer on redirect CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect CURLOPT_TIMEOUT => 120, // timeout on response CURLOPT_MAXREDIRS => 10, // stop after 10 redirects ); $ch = curl_init( $url ); curl_setopt_array( $ch, $options ); $content = curl_exec( $ch ); $err = curl_errno( $ch ); $errmsg = curl_error( $ch ); $header = curl_getinfo( $ch ); curl_close( $ch ); $header['errno'] = $err; $header['errmsg'] = $errmsg; $header['content'] = $content; print_r($header); return $content; }
I am prompted for a connection method on my phone but then immediately get:Code:echo "START<br>"; echo get_web_page("http://google.com/"); echo "END<br>";
START
Array ( [url] => http://google.com/ [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0 [namelookup_time] => 0 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => 0 [upload_content_length] => 0 [starttransfer_time] => 0 [redirect_time] => 0 [errno] => 7 [errmsg] => couldn't connect to host [content] => ) END
I have also tried requesting local files on the web server
echo get_web_page("http://localhost/textfile.txt");
gives an error that host 0.0.0.0 is invalid
echo get_web_page("http://127.0.0.1/textfile.txt");
seems to time out I only get the START text
echo get_web_page("http://LANIPADDRESS/textfile.txt");
also seems to time out
echo get_web_page("/textfile.txt");
[errno] => 3 [errmsg] => malformed [content]
I have also tried to raise the time out time.
Anyone who knows what the problem might be and how it could be overcome? Some alternative solution that could be used to create requests?
regards,
Magnus



