[英]file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded
i have a project by php and javascript... I have a Call an API from Camera by Php code.我有一个 php 和 javascript 的项目...我有一个 API 来自相机的电话 Z2EC543BDE83A1A3ED7EB06766Z 代码。 I used (file_get_contents) function and Post request: this Code:
我使用 (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);
//}
}
this code is working and Camera take picture but problem is that I alway get this Notice:此代码正在运行并且相机拍照但问题是我总是收到此通知:
Notice: file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded in C:\xampp7.3\htdocs\CameraTest\function.php on line 63注意:file_get_contents():内容类型未指定,假设 application/x-www-form-urlencoded 在第 63 行 C:\xampp7.3\htdocs\CameraTest\function.php
And I send Values to php file by Ajax Call from Java Script File this is code in Java script file:我通过从 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); }
please i want no more get this Notice I hope your help and thanks so much请我不要再收到此通知我希望您的帮助和非常感谢
Looking at the implementation (eg PHP 7.4.0 , PHP 8.1.0 ), it looks like the header won't be detected if there is a space between the header name and the colon. Looking at the implementation (eg PHP 7.4.0 , PHP 8.1.0 ), it looks like the header won't be detected if there is a space between the header name and the colon. This is possibly a bug, but one that's easy to work around - instead of:
这可能是一个错误,但很容易解决 - 而不是:
'header' => "Content-Type : application/json"
Try:尝试:
'header' => "Content-Type: application/json"
Edit your header in PHP, change the Content-type from application/json
to application/x-www-form-urlencoded
.在 PHP 中编辑您的 header,将 Content-type 从
application/json
更改为application/x-www-form-urlencoded
。 So your code should be:所以你的代码应该是:
...
'timeout' => 60,
'content' => $post,
'header' => "Content-Type: application/x-www-form-urlencoded"
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.