문제

I'm a building a RESTful API using Zend Framework 2 and Apigility by Zend Framework. For testing, I use the chrome extension Postman REST-Client.

I can do GET requests and POST requests without problems by sending form-data without problems.

But when I try to do a PUT, PATCH or DELETE request, I get the following error:

{
    "type":"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
    "title":"Unsupported Media Type",
    "status":415,
    "detail":"Invalid content-type specified"
}

Accept whitelist in Rest-Service-Config of Apigility:

application/vnd.timber-ms.v1+json, application/hal+json, application/json

Content-Type whitelist:

application/vnd.timber-ms.v1+json, application/json

The content-type of the response is application/problem+json

What can I do to fix this and do successfull PUT/PATCH requests? Is this a problem with Postman or Apigility?

도움이 되었습니까?

해결책

You're getting the 415 error of Unsupported Media Type when Apigility cannot deserialize the data coming from the client. This recently was called out in the documentation.

I suspect your problem is due to the content-type being sent from postman. Pay special attention to the Content-Type Whitelist listed for the service and make sure it contains the content-type you are sending.

For example, if your service has only has application/json in the Content-Type Whitelist and you send the PUT/PATCH with postman as x-www-form-urlencoded, you will get a 415 error of Unsupported Media Type. If you change postman to send the PUT/PATCH with a content-type of application/json and the request body contains valid JSON, Apigility should accept the request.

You can check the content-type postman is sending by clicking on the "Preview" button just to the right of the "Send" button.

다른 팁

I was having a similar issue in Postman with the unsupported media type responses. However, I experienced this response on both PUT and POST requests using my company's API.

I verified that Postman was the problem here and not the request/API in use by running the same request with another similar Chrome extension called Advanced REST Client. I'm not familiar with Apigility, but pretty sure that Postman is the culprit here.

Hoping there is a fix for this issue as Postman and its collections feature is much easier to use than that of Advanced REST Client.

I had the same problem,

My solution was to write my data to [Body] in the [raw] in json format. Like this:

{"message": "UPDATED First Post!"}

And in [Headers] :

[KEY]   Content-Type 
[Value] application/json
  • on postman go to normal tab (or other auths tab) and add header:

    Content-Type application/json (or any type you need)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top