所以這是我第一次構建 REST API,當我使用 localhost 測驗 API 時,它的作業就像一個魅力,但是當我在托管上托管 REST API 專案時它突然不起作用。GET 和 POST 功能仍然有效,但 DELETE 和 PUT 功能不可用。
我使用 000webhost 免費托管作為我的測驗平臺。
我在控制器上的洗掉功能:
public function delete($id = null)
{
$model = new BarangModel();
$data = $model->where('id_barang', $id)->delete($id);
if ($data) {
$model->delete($id);
$response = [
'status' => 200,
'error' => null,
'messages' => [
'success' => 'Barang berhasil dihapus!'
]
];
return $this->respondDeleted($response);
} else {
return $this->failNotFound('No employee found');
}
}
我的型號代碼:
class BarangModel extends Model
{
protected $DBGroup = 'default';
protected $table = 'tb_barang';
protected $primaryKey = 'id_barang';
protected $useAutoIncrement = true;
protected $insertID = 0;
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $allowedFields = ['kode', 'nama', 'merk', 'tahun', 'jumlah', "ruangan", 'penguasaan', 'keterangan'];
// Dates
protected $useTimestamps = false;
protected $dateFormat = 'datetime';
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
protected $deletedField = 'deleted_at';
// Validation
protected $validationRules = [];
protected $validationMessages = [];
protected $skipValidation = false;
protected $cleanValidationRules = true;
// Callbacks
protected $allowCallbacks = true;
protected $beforeInsert = [];
protected $afterInsert = [];
protected $beforeUpdate = [];
protected $afterUpdate = [];
protected $beforeFind = [];
protected $afterFind = [];
protected $beforeDelete = [];
protected $afterDelete = [];
}
控制臺中的錯誤代碼:
Error: Network Error
at t.exports (createError.js:16:15)
at XMLHttpRequest.b.onerror (xhr.js:117:14)
ae @ vue.runtime.esm.js:1897
re @ vue.runtime.esm.js:1888
ne @ vue.runtime.esm.js:1848
(anonymous) @ vue.runtime.esm.js:1865
Promise.catch (async)
ie @ vue.runtime.esm.js:1865
n @ vue.runtime.esm.js:2188
ie @ vue.runtime.esm.js:1863
In.t.$emit @ vue.runtime.esm.js:3903
click @ VBtn.ts:163
ie @ vue.runtime.esm.js:1863
n @ vue.runtime.esm.js:2188
Qr.a._wrapper @ vue.runtime.esm.js:6961
xhr.js:210
DELETE https://xxx.000webhostapp.com/api/index.php/barang/106 net::ERR_HTTP2_PROTOCOL_ERROR
(anonymous) @ xhr.js:210
t.exports @ xhr.js:15
t.exports @ dispatchRequest.js:58
u.request @ Axios.js:108
i.forEach.u.<computed> @ Axios.js:129
(anonymous) @ bind.js:9
(anonymous) @ Barang.vue:292
u @ runtime.js:63
(anonymous) @ runtime.js:294
(anonymous) @ runtime.js:119
i @ asyncToGenerator.js:3
s @ asyncToGenerator.js:25
(anonymous) @ asyncToGenerator.js:32
(anonymous) @ asyncToGenerator.js:21
t @ Barang.vue:291
ie @ vue.runtime.esm.js:1863
n @ vue.runtime.esm.js:2188
ie @ vue.runtime.esm.js:1863
In.t.$emit @ vue.runtime.esm.js:3903
click @ VBtn.ts:163
ie @ vue.runtime.esm.js:1863
n @ vue.runtime.esm.js:2188
Qr.a._wrapper @ vue.runtime.esm.js:6961
在郵遞員上,它顯示“套接字掛起”錯誤。
uj5u.com熱心網友回復:
PUT 和 DELETE 方法不適用于000webhost上的免費托管。您必須升級到 Premium 計劃才能使用 GET 和 POST 以外的 HTTP 方法。請參閱這篇文章。
除了 GET 和 POST 之外的所有方法都簡單地以免費托管計劃終止。在我看來,這對他們來說是非常業余的,因為他們可以很容易地發送一個回應標頭說“僅適用于高級計劃”,而不是直接終止連接。
與此同時,開發人員正在浪費大量時間試圖找出他們完美的代碼出了什么問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/462555.html
上一篇:使用api構建表與反應表
下一篇:“應解碼Dictionary<String,Any>但找到了一個陣列。”,underlyingError:nil;GitHub存盤庫顯示應用程式;SwiftUI
