gpt4 book ai didi

windows - Yii2 REST API IIS 对象移动

转载 作者:可可西里 更新时间:2023-11-01 10:32:57 26 4
gpt4 key购买 nike

我正在使用 Yii2 REST 和 ActiveController 创建一个 new Pessoa(),在 Apache 上工作正常,但在 IIS 8 上发生错误。

有人知道 IIS 中的任何配置吗?

REQUEST

Request URL:http://10.192.1.145/api/pessoa
Request Method:POST
Status Code:201 Created
Remote Address:10.192.1.145
Referrer Policy:no-referrer-when-downgrade

RESPONSE

<head><title>Document Moved</title></head>
<body><h1>Object Moved</h1>This document may be found
<a HREF="http://10.192.1.145/api/pessoa/45">here</a></body>{"id":"21"}

最佳答案

我遇到了类似的问题。好像跟FastCGI有关。不确定。我知道将响应 header 设置为 201 http 状态代码 ( this line in source code ) 时会发生这种情况,稍后会被 IIS 更改。如果您有权访问服务器,请尝试这些解决方案:

W7 Pro IIS 7.5 overwrites PHP Location: Header (solved)

在我的例子中,我只有 FTP 访问服务器,所以我通过类似下面的内容覆盖了创建操作,以强制使用 200 状态代码而不是 201:

public function actions()
{
$actions = parent::actions();
unset($actions['create']);
return $actions;
}

public function actionCreate() {
$model = new Pessoa();
$model->load(Yii::$app->getRequest()->getBodyParams(), '');
if ($model->save() === false && !$model->hasErrors()) {
throw new ServerErrorHttpException('Failed to update the object for unknown reason.');
}
return $model;
}

关于windows - Yii2 REST API IIS 对象移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43618117/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com