Code Monkey home page Code Monkey logo

Comments (7)

chentianming11 avatar chentianming11 commented on May 24, 2024

按照HTTP规范,get请求方式就是不支持请求体的😂
所以,不太理解“Get方法,并且须带有一个Json格式的body”具体指什么。

from retrofit-spring-boot-starter.

leesonwei avatar leesonwei commented on May 24, 2024

按照HTTP规范,get请求方式就是不支持请求体的😂
所以,不太理解“Get方法,并且须带有一个Json格式的body”具体指什么。

感谢您的回复:
我这里有个API,它的文档如下:
`GET /consumers/testgroup/instances/my_consumer/offsets HTTP/1.1
Host: proxy-instance.kafkaproxy.example.com
Content-Type: application/vnd.kafka.v2+json, application/vnd.kafka+json, application/json
#parameters
{
"partitions": [
{
"topic": "test",
"partition": 0
},
{
"topic": "test",
"partition": 1
}

]
}`
如果使用postman, 把parameters放到body中即可. 但是retrofit不支持.
所以请教应该如何用retrofit创建该请求?谢谢!

from retrofit-spring-boot-starter.

chentianming11 avatar chentianming11 commented on May 24, 2024

今天查了下,get确实可以传body,但是一般不推荐这么使用。我研究一下retrofit怎么传😂,之前没碰到过

from retrofit-spring-boot-starter.

chentianming11 avatar chentianming11 commented on May 24, 2024

@HTTP(method = "GET", path = "/user/get", hasBody = true)
试试这种方式看看~

from retrofit-spring-boot-starter.

leesonwei avatar leesonwei commented on May 24, 2024

@HTTP(method = "GET", path = "/user/get", hasBody = true)
试试这种方式看看~

感谢, 这个方式报错信息意思一样. 还是通不过

from retrofit-spring-boot-starter.

chentianming11 avatar chentianming11 commented on May 24, 2024

@HTTP(method = "GET", path = "/user/get", hasBody = true)
试试这种方式看看~

感谢, 这个方式报错信息意思一样. 还是通不过

okhttp3自身不支持GET请求带请求体。源码如下:
image
image

作者给出了具体原因,可以参考这个issue:square/okhttp#3154

but,如果实在需要这么干,我想到一种方式,可以使用@HTTP(method = "get", path = "/user/get", hasBody = true)。使用小写get绕过上述限制。可以尝试一下!

from retrofit-spring-boot-starter.

leesonwei avatar leesonwei commented on May 24, 2024

谢谢. 不过小写的get对我不起作用, kafka端不允许get请求,只允许GET请求. 不过我看了很多http客户端(apache httpclient, spring webclient等), 基本上都不支持get带body. 看来只能用最原始的方法了. 再次谢谢您的帮助!

from retrofit-spring-boot-starter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.