question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type of request is changed from GET to POST

See original GitHub issue

Ktor 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:closed
  • Created 5 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nbaklanov-issartcommented, Dec 19, 2018

Could you also post platform-specific dependencies?

      sourceSets {
        commonMain {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
                implementation("io.ktor:ktor-client:$ktor_version")
                implementation("io.ktor:ktor-client-json:$ktor_version")
            }
        }
        commonTest {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-test-common'
                implementation 'org.jetbrains.kotlin:kotlin-test-annotations-common'
            }
        }
        androidMain {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-stdlib'
                implementation("io.ktor:ktor-client-android:$ktor_version")
            }
        }
        androidTest {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-test'
                implementation 'org.jetbrains.kotlin:kotlin-test-junit'
            }
        }
        iosMain {
            dependencies {
                implementation("io.ktor:ktor-client-ios:$ktor_version")
            }
        }
        iosTest {
        }
    }
0reactions
e5lcommented, Mar 19, 2019

Fixed in master.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found