简体   繁体   English

file_get_contents():假设应用程序/x-www-form-urlencoded 未指定内容类型

[英]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.

相关问题 的file_get_contents( 'PHP://输入'); 与application / x-www-form-urlencoded; - file_get_contents('php://input'); with application/x-www-form-urlencoded; "ajax、setRequestHeader()、Content-Type、application\/x-www-form-urlencoded 和 charset" - ajax, setRequestHeader(), Content-Type, application/x-www-form-urlencoded and charset 无法通过“Content-Type”发送 JSON object:“application/x-www-form-urlencoded - Unable to send JSON object over “Content-Type”: "application/x-www-form-urlencoded “axios.defaults.headers.common['Content-Type'] = 'application/json'” 但 axios.post 仍然是“application/x-www-form-urlencoded” - "axios.defaults.headers.common['Content-Type'] = 'application/json'" but axios.post still is "application/x-www-form-urlencoded" 使用 apollo-datasource-rest 库将 Content-Type 标头设置为 application/x-www-form-urlencoded - Setting Content-Type header to application/x-www-form-urlencoded using apollo-datasource-rest library 当我的dataType:“ JSON”时,为什么我的Ajax请求发送“内容类型:application / x-www-form-urlencoded”? - Why is my Ajax request sending “Content-Type: application/x-www-form-urlencoded” when I have dataType: “JSON”? 使用 x-www-form-urlencoded content-type 将嵌套的 object 作为 formdata 发布 - post nested object as formdata using x-www-form-urlencoded content-type 如何使用在Content-Type标头中同时具有“ application / x-www-form-urlencoded”和“ charset = UTF-8”的Javascript发布HTML表单 - How to post a HTML form using Javascript that has both “application/x-www-form-urlencoded” and “charset=UTF-8” in the Content-Type header 使用字符串作为请求正文时,为什么 Axios 发送我的 POST 请求时使用 Content-Type application/x-www-form-urlencoded? - Why does Axios send my POST request with Content-Type application/x-www-form-urlencoded when using a string as the request body? HttpMediaTypeNotSupportedException:不支持内容类型 'application/x-www-form-urlencoded;charset=UTF-8' - HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM