Reputation: 5458
Trying to post to a url, and recieve an image.
for example (this works in the browser):
my code:
$url = 'https://providers.cloudsoftphone.com/lib/prettyqr/createQR.php';
$fields = array(
'user'=> 123,
'pass'=> 321,
'cloudid'=> 'test',
'format'=> 'png'
);
$options = array(
'http' => array(
'header' => 'Content-type: application/x-www-form-urlencoded',
'method' => 'POST',
'content' => http_build_query($fields)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
var_dump($result);
tried following this answer.
returns "invalid input"
**EDIT**
also trying with curl:
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec( $ch );
var_dump($response);
same result ('invalid input')
Upvotes: 3
Views: 168
Reputation: 1609
You can use JQuery
to send a post request and then take the respons via Jquery
<input type="button" name="bttnLoadQR" onClick=" $.post( "https://providers.cloudsoftphone.com/lib/prettyqr/createQR.php", { user: "123", pass: "321", cloudid: "test", format: "png" }, function(data){ $('#result').html(data); }); "> <div id="result"></div>
Check here http://jsfiddle.net/S8Lgp/212/
Upvotes: 0
Reputation: 12233
Check this
You should add parameters to query instead of context which is not necessary at all
$url = 'https://providers.cloudsoftphone.com/lib/prettyqr/createQR.php';
$fields = array(
'user'=> 123,
'pass'=> 321,
'cloudid'=> 'test',
'format'=> 'png'
);
$result = file_get_contents($url."?".http_build_query($fields));
var_dump($result);
Upvotes: 1