Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
872 views
in Technique[技术] by (71.8m points)

api - Error 415 Unsupported Media Type for GET method

I'm currently working through the Mulesoft Mule 4 Fundamentals course and have deployed an application on Runtime Manager.

When I look in the logs of my application on Runtime Manager and the logs of Anypoint Studio I see the above "Unsupported Media Type" error when testing a GET HTTP request. I also get this error when testing in ARC.

When I look in the Mule debugger and then the payload in Anypoint Studio I see mediaType = */* charset = UTF-8

I thought that this does not need to be added for GET requests, so how do I get around this?

My RAML file:

#%RAML 1.0
title: session-2

types:
  newsProperties: !include schemas/newsDataType.raml

/search:
  get:
    headers:
      Accept:
        default: application/json
    queryParameters:
      keyword:
        type: string
        minLength: 3
        maxLength: 10
    responses:
      200:
        body:
          application/json:
            example: !include examples/searchExample.raml
      400:
        body:
          application/json:
            example:
              {"message": "Search query too long"}
/news:
  post:
    queryParameters:
      country:
        required: false
    body:
      application/json:
        type: newsProperties
    responses:
      201:
        body:
          application/json:
            example: !include examples/searchExample.raml

/sportsNews:
  put:
    body:
      application/json:
        type: newsProperties

The header in the /search resource GET method has been added recently after searching online and trying a number of different solutions I've seen, but I am still getting the same error. Any help would be appreciated.

Thanks!

question from:https://stackoverflow.com/questions/65882344/error-415-unsupported-media-type-for-get-method

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Probably you are not setting the Content-Type header to application/json and the API implementation is expecting it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...