i have a project by php and javascript ... I have a Call an API from Camera by Php code. I used (file_get_contents) function and Post request: this Code:
$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
And I send Values to php file by Ajax Call from Java Script File this is code in Java script file :
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
CodePudding user response:
Looking at the implementation (e.g. 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"
CodePudding user response:
Edit your header in PHP, change the Content-type from application/json
to application/x-www-form-urlencoded
. So your code should be:
...
'timeout' => 60,
'content' => $post,
'header' => "Content-Type: application/x-www-form-urlencoded"
...