Type of request is changed from GET to POST
See original GitHub issueKtor Version
ktor_version = 1.0.1
Ktor Engine Used(client or server and name)
Ktor Clients
JVM Version, Operating System and Relevant Context
Android API 22
Feedback
Hi, everyone, I have a simple request code :
protected fun sendGetRequest(requestBody:Any = EmptyContent,
parameters:List<Pair<String, String>> = emptyList(),
requestHeaders:List<Pair<String, String>> = emptyList()) {
GlobalScope.launch(CoroutineContextProvider.provideContext()) {
try {
val call = client.request<HttpResponse> {
url{
protocol = URLProtocol.HTTP
//port = serverPort
host = serverAddress
encodedPath = requestEncodedPath
}
method = HttpMethod.Get
body = requestBody
for (currentPair:Pair<String, String> in requestHeaders) {
headers.append(currentPair.first, currentPair.second)
}
for (currentPair:Pair<String, String> in parameters) {
parameter(currentPair.first, currentPair.second)
}
}
requestResponseHandler(call, call.readText())
} catch (requestException:Exception) {
requestExceptionHandler(requestException)
}
}
}
It’s get request. But when I call this function like this :
val headers:MutableList<Pair<String, String>> = mutableListOf()
headers.add(Pair("Authorization", "Bearer $token"))
val body:ByteArrayContent = ByteArrayContent(fileBytes)
sendGetRequest(requestBody = body, requestHeaders = headers)
I will get response like : Request method POST not supported. And in proxy logs I see that ktor really sending POST. If I will remove body from request - ktor will send get, but server will not accept this because it’s waiting parameters in body.
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Changing from GET to POST - Stack Overflow
I changed your request Methods from GET to POST here. ... Note: The request data is stilled parsed into the URL of your...
Read more >GET vs POST - Difference and Comparison | Diffen
HTTP POST requests supply additional data from the client (browser) to the server in the message body. In contrast, GET requests include all...
Read more >How to change GET request to POST request? - MSDN
I am writing to seek help, in how can i change the following GET response method to POST method. I have tried many...
Read more >HTTP Request Methods – Get vs Put vs Post Explained with ...
In this article, we'll be discussing the get, put, and post HTTP methods. You'll learn what each HTTP method is used for as...
Read more >Is get and post interchangeable?
There is a significant reason why GET and POST are not interchangeable. On websites that use session cookie. GET requests will include the ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed in
master
.