【问题标题】:Laravel 5.7 API return 302Laravel 5.7 API 返回 302
【发布时间】:2018-12-20 05:05:43
【问题描述】:

我正在使用 Laravel 5.7 创建 REST API,它总是返回 302 和重定向响应,HTML 代码如下

<!DOCTYPE html><html>
<head>

    <meta charset="UTF-8" />
    <meta http-equiv="refresh" content="0;url=http://localhost/Ozone/en" />

    <title>Redirecting to http://localhost/Ozone/en</title>
</head>
<body>
    Redirecting to <a href="http://localhost/Ozone/en">http://localhost/Ozone/en</a>.
</body>

{
    "status": false,
    "message": "Input are not valid",
    "error":
        {
            "contact_number": ["The contact number has already been taken."]
        }
}

我只想要类似 JSON 响应

{
    "status": false,
    "message": "Input are not valid",
    "error": {
        "contact_number": ["The contact number has already been taken."]
    }
}

请帮帮我

【问题讨论】:

  • 您的请求是否有Accept:application/json 请求标头值?
  • 是接受:application/json
  • 如果框架返回重定向是因为您使用的是 FormRequest 和规则?我说的对吗?

标签: laravel rest api


【解决方案1】:

如果你wantjson响应,需要在请求头中包含Accept:application/json。

【讨论】:

  • 如果您的问题仍然存在,请使用请求标头更新您的问题。
  • 以前工作正常,突然会发送 302 Found ,我不知道为什么
  • Ca update the question with the script you are used to make api calls ?
  • 一切正常,除了返回响应额外的 HTML 响应
  • 看不到脚本中的内容,无法解决您的问题。请使用相关代码更新问题。您只发布了错误消息。
猜你喜欢
  • 2019-10-23
  • 2019-05-24
  • 1970-01-01
  • 2015-04-14
  • 1970-01-01
  • 2019-08-13
  • 2019-05-16
  • 2019-05-26
  • 2017-10-13
相关资源
最近更新 更多