错误信息:
Notice: file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded in D:\WWW\http\http_request.php on line 14
Warning: file_get_contents(http://localhost/http/write_sql.php): failed to open stream: HTTP request failed! in D:\WWW\http\http_request.php on line 14
bool(false)
源代码:
<?php
$content = ['title'=>"1'da",'con'=>'lai'];
$content = http_build_query($content);
// 制作http请求头
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Host:localhost\r\n'."Content-type:application/x-www-form-urlencoded\r\n"."Content-length:".strlen($content)."\r\n",
"content" => $content,
)
);
$context = stream_context_create($opts);
// 文件内容请求
var_dump(file_get_contents("http://localhost/http/write_sql.php", false, $context));
出错原因:php中的单引号不解析\r\n等能不能解析
然后该为双引号,就可以正常运行了