![](/img/trans.png)
[英]file_get_contents('php://input'); with application/x-www-form-urlencoded;
[英]file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded
我有一個 php 和 javascript 的項目...我有一個 API 來自相機的電話 Z2EC543BDE83A1A3ED7EB06766Z 代碼。 我使用 (file_get_contents) function 和發布請求:此代碼:
$value = $_POST['TakeNewPic'];
function Takepic(){
$Parametrs = $value;
$opts = array(
"user" => "THETAYN10113693",
"password" => "10113693",
"name" => $Parametrs
);
$post = json_encode($opts);
$context = stream_context_create(array(
'http' => array(
'method' => "POST",
'timeout' => 60,
'content' => $post,
'header' => "Content-Type : application/json"
)
));
$url = 'http://192.168.1.1/osc/commands/execute';//.$https_server;
$result = file_get_contents($url,false, $context);
echo json_encode($result);
//}
}
此代碼正在運行並且相機拍照但問題是我總是收到此通知:
注意:file_get_contents():內容類型未指定,假設 application/x-www-form-urlencoded 在第 63 行 C:\xampp7.3\htdocs\CameraTest\function.php
我通過從 Java 腳本文件調用 Ajax 將值發送到 php 文件,這是 ZD5238972 腳本文件75921381 中的代碼:
function getCamInfo(value) { var body = "TakeNewPic=" + value; var req = new XMLHttpRequest(); req.onreadystatechange = function () { if(this.readyState === 4 && this.status === 200){ var res = document.getElementById("parg"); res.innerHTML =this.responseText; } } req.open ( "POST", "post_req.php", true, ); req.setRequestHeader( "content-type", "application/x-www-form-urlencoded" ); req.send(body); } document.getElementById("butt").onclick = function () { getCamInfo("camera.takePicture"); //console.log(AllInfo); }
請我不要再收到此通知我希望您的幫助和非常感謝
在 PHP 中編輯您的 header,將 Content-type 從application/json
更改為application/x-www-form-urlencoded
。 所以你的代碼應該是:
...
'timeout' => 60,
'content' => $post,
'header' => "Content-Type: application/x-www-form-urlencoded"
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.