- 我的密码**
<?php
if($_SERVER["REQUEST_METHOD"]=="POST"){
$title = $_POST["title"];
$type = $_POST["type"];
$content = $_POST["content"];
$description = $_POST['description'];
$postdata =
array(
'title' => $title,
'type' => $type,
'content' => $content,
'description' => $description,
);
$opts = array('http' =>
array(
'method' => 'POST',
'content' => http_build_query($postdata),
)
);
$context = stream_context_create($opts);
$result = file_get_contents('http://localhost:8080/project_war_exploded/admin/blog', false, $context);
echo $result;
}
?>
我收到错误"文件获取内容(http://localhost:8080/project_war_exploded/admin/blog)":无法打开流:HTTP请求失败! HTTP/1.1 415 "
原因是什么,有人能帮我吗?
就像我说的-从 Postman 那里打电话,效果很好。有什么建议吗?
1条答案
按热度按时间qxsslcnc1#
415表示
Unsupported media type
。您发送了后端不期望的www-form-urlencoded
。将正确的内容类型添加到头中,如本例中的application/json