Open brihoumb opened 5 years ago
Hi there!
GET bodies don't work < 2.0.0; I am unsure if they work in 2.0.0 but I'll personally see if we can have that added!
Is there tricks for doing it now ? Or do I need to code it by myself until version 2.0.0 came out ?
By according to HTTP Standard, GET should not have request body because it only do query strings. As for upload function, you should use POST methods.
@iNoles that was dropped from the RFC. GET requests may have bodies now.
This answers a similar question I had. I have a GET request and I have to pass a structure to the server to generate a file and send it back. In my case the structure is small so I can put it all in query strings. However, there are other cases where it becomes a real burden to do so and it is much simpler to have a structured object that is serialized as JSON in the body of the request. Is there a way to accommodate this?
Hi, I would also really like this feature to work :) Am struggling to interact with an API without this at the moment.
If anyone would love to take this, I am happy to accept PR :) Otherwise, I will try to see what I can do for this.
Android's HttpURLConnection is extremely legacy in back to Java 6. OkHttp doesn't have this kind of the feature. in Ktor, It will give warning in https://github.com/ktorio/ktor/blob/master/ktor-client/ktor-client-android/jvm/src/io/ktor/client/engine/android/AndroidClientEngine.kt#L63
Not allow to send body in GET
request is a strange restriction. As @SleeplessByte said that unreasonable constraint was already dropped from the RFC.
Meanwhile many famous projects' apis take body in GET
request (Elasticsearch for example).
GET /_search
{
"query": {
"multi_match": {
"query": "this is a test",
"fields": [
"subject",
"message"
]
}
}
}
So will fuel
plan to remove the restriction? Otherwise we have to use POST
method to get something when the query is complicated (hope luckily the server support both post and get).
If anyone would love to take this, I am happy to accept PR :) Otherwise, I will try to see what I can do for this.
⬆️
@SleeplessByte @kittinunf
I am not sure but it seams that send or drop the body is controlled by this function. Maybe move Method.GET
down is enough? I tried but didn't solve the compilation environment for this project. Is anyone else willing to help?
https://github.com/kittinunf/fuel/blob/f16bd8e30c73812c20d46b5c0368829b4867daa2/fuel/src/main/kotlin/com/github/kittinunf/fuel/toolbox/HttpClient.kt#L274-L277
I'm afraid there isn't much we can do to make it work as the underlying HttpURLConnection does some weird thing for some unknown to me backward compatibility reasons:
if (method.equals("GET")) {
method = "POST"; // Backward compatibility
}
I know GET should not have request body, but I need to fetch data from a site implemented in this way :(
I'm unable to send body with Fuel v2.3.1 but maybe what I found could help the fix: this is my code
val myGet = "https://webhook.site/210d9c41-b0a1-48fa-b2e5-0b28d89831c8"
.httpGet()
.jsonBody("""{"test":"EdVXcwrUCkJu2T2mUfAgzemvSDDxYqDLECvx24Wk"}""")
.responseString { request, response, result ->
println(request.cUrlString())
}
myGet.join()
it prints this cURL that doesn't send body
curl -i -d "{\"test\":\"EdVXcwrUCkJu2T2mUfAgzemvSDDxYqDLECvx24Wk\"}" -H "Content-Type:application/json" https://webhook.site/210d9c41-b0a1-48fa-b2e5-0b28d89831c8
BUT if I add --request GET
to the cURL it sends the body
curl -i --request GET -d "{\"test\":\"EdVXcwrUCkJu2T2mUfAgzemvSDDxYqDLECvx24Wk\"}" -H "Content-Type:application/json" https://webhook.site/210d9c41-b0a1-48fa-b2e5-0b28d89831c8
Hi @emanuele-dedonatis . Unfortunately we're still constraint by the underlying HTTP library.
I'm creating an android app using Fuel for kotlin and i need to send a GET request to the server with a body but got "Exception : method does not support a request body: GET". How can I send a body with my GET request ?
I follow you my function: