我有一个适用于 GET 协议(protocol)的 API。
我正在尝试使用 POST,但无法访问它。
使用 Vagrant SSH 或测试站点,它被拒绝了:
vagrant@smyprojectt:~$ curl -X POST -v http://127.0.0.1:8080/api/xml/
* Trying 127.0.0.1...
* TCP_NODELAY set
* connect to 127.0.0.1 port 8080 failed: Connection refused
* Failed to connect to 127.0.0.1 port 8080: Connection refused
* Closing connection 0
curl: (7) Failed to connect to 127.0.0.1 port 8080: Connection refused
在外面直接做给了我这个答案:
me@myuser:~$ curl -X POST -v http://127.0.0.1:8080/api/xml/
* Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> POST /api/xml/ HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Wed, 09 Jan 2019 09:50:46 GMT
< Server: Apache/2.4.25 (Debian)
< Location: http://127.0.0.1:8080/api/xml
< Content-Length: 322
< Content-Type: text/html; charset=iso-8859-1
<
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://127.0.0.1:8080/api/xml">here</a>.</p>
<hr>
<address>Apache/2.4.25 (Debian) Server at 127.0.0.1 Port 8080</address>
</body></html>
* Connection #0 to host 127.0.0.1 left intact
应用程序的其余部分工作正常,包括 AJAX 或使用 POST 的表单,但这个请愿书特别被拒绝。
有什么帮助吗?
最佳答案
每个 POST/PATCH/PUT/DELETE 请求都使用 CSRF token 进行验证。因此,您要么在请求中传递 token ,要么在 Http/Kernel.php
文件中注释掉 \App\Http\Middleware\VerifyCsrfToken::class,
$middlewareGroups
数组为了测试。
关于laravel - 使用 Vagrant 执行 POST 请求时连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54107356/