laravel - 使用 Vagrant 执行 POST 请求时连接被拒绝

标签 laravel http post vagrant

我有一个适用于 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/

相关文章:

php - 目标 [League\OAuth2\Server\Repositories\ClientRepositoryInterface] 在构建 [League\OAuth2\Server\AuthorizationServer] 时不可实例化

C++访问url日志

javascript - 异步 POST 到数据库时出现问题

javascript - angular2 http.post() 到本地 json 文件

php - Laravel 连接子查询

php - 在 Laravel 测试用例中模拟一个 http 请求并解析路由参数

php - SQLSTATE[23000] : Integrity constraint violation: 1048 Column 'property_id' cannot be null in Laravel 5. 2

node.js - 将 .htacees 指向使用 SSL 配置的 Node 服务器

http - Node.js:在检索 http 请求正文之前断开 http 请求连接

c# - Response.Redirect 正在执行 POST 而不是 GET