0


http409 415报错原因

409

今天一个同事的接口突然报409,大概百度了一下,不是很清楚,谷歌也没找到特别好的解释

因为是直接调用的gitlab,就直接看了下gitlab的api

The following table shows the possible return codes for API requests.
Return valuesDescription

200 OK

The

GET

,

PUT

or

DELETE

request was successful, and the resource itself is returned as JSON.

202 Accepted

The

GET

,

PUT

or

DELETE

request was successful, and the resource is scheduled for processing.

204 No Content

The server has successfully fulfilled the request, and there is no additional content to send in the response payload body.

201 Created

The

POST

request was successful, and the resource is returned as JSON.

304 Not Modified

The resource hasn't been modified since the last request.

400 Bad Request

A required attribute of the API request is missing. For example, the title of an issue is not given.

401 Unauthorized
403 Forbidden

The request isn't allowed. For example, the user isn't allowed to delete a project.

404 Not Found

A resource couldn't be accessed. For example, an ID for a resource couldn't be found.

405 Method Not Allowed

The request isn't supported.

409 Conflict

A conflicting resource already exists. For example, creating a project with a name that already exists.

412

The request was denied. This can happen if the

If-Unmodified-Since

header is provided when trying to delete a resource, which was modified in between.

422 Unprocessable

The entity couldn't be processed.

429 Too Many Requests

The user exceeded the application rate limits.

500 Server Error

While handling the request, something went wrong on the server.
gitlab解释的很清晰,就是说资源已经存在了,再次创建失败

那为什么接口没有将报错message展示出来,查了一下代码是因为直接屏蔽了409状态码,直接用postman访问接口会返回具体错误信息,错误提示信息示例:

示例1:

{

"message": "Email has already been taken"

}

示例2:

{

"message": "Username has already been taken"

}

找gitlab负责人查了下数据,确实是用户已经存在了,但是用户状态是blocked(禁用),问题解决

-----------------------------------我是分割线-----------------------------------

415

    好巧不巧,今天又一个项目遇到了一个奇怪的错误码415,平时开发不常见,让我去帮忙排查

    先简单了解了一下,服务A直接通过postman调用是可以的,但是就是别的服务调用服务A响应415,先百度,直接说是请求头不支持导致的

    查看postman请求头,Content-Type是application/json;改下请求头(直接取消传递Content-Type,默认),响应415,具体响应内容如下
{

    "timestamp": "2023-02-14T09:55:54.342+0000",

    "status": 415,

    "error": "Unsupported Media Type",

    "message": "Content type 'application/octet-stream' not supported",

    "path": "/zhanye-admin/iam/sync/SchemaService"

}

改成text/plain,则响应还是415,具体响应

{

    "timestamp": "2023-02-14T09:58:07.376+0000",

    "status": 415,

    "error": "Unsupported Media Type",

    "message": "Content type 'text/plain;charset=UTF-8' not supported",

    "path": "/zhanye-admin/iam/sync/SchemaService"

}

基本能确定是调用方请求头的问题,但是调用方说自己调用没问题,调用服务A跟调用别的系统都一样,别的服务都正常,就是服务A一直报错,服务A的开发同学也很委屈,我postman调用正常...

    那就直接curl调用一下试试吧,直接在B服务所在的服务器调用A服务,正常,ok,这就确定了是B服务调用的问题,直接将调用请求和响应截图给B服务开发同学,让他排查问题,最终发现B服务的请求头中Content-Type不是application/json,而是text/plain
标签: postman 测试工具

本文转载自: https://blog.csdn.net/wangwenzhe222/article/details/129008463
版权归原作者 AscendKing 所有, 如有侵权,请联系我们删除。

“http409 415报错原因”的评论:

还没有评论