[英]PHP post to api, receive an image
試圖發布到網址,並收到圖像。
例如(這在瀏覽器中有效):
我的代碼:
$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);
試着按照這個答案。
返回“無效輸入”
**編輯**
也嘗試卷曲:
$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);
相同的結果('無效輸入')
檢查一下
您應該添加參數來查詢而不是根本不需要的上下文
$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);
您可以使用JQuery
發送帖子請求,然后通過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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.