Antero Duarte
08/10/2018, 2:03 PMDEBUG org.apache.http.wire - http-outgoing-0 >> "POST /the/endpoint HTTP/1.1[\r][\n]"
DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Type: x-www-form-urlencoded[\r][\n]"
DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept: */*[\r][\n]"
DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Length: 201[\r][\n]"
DEBUG org.apache.http.wire - http-outgoing-0 >> "Host: localhost:8888[\r][\n]"
DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent: Apache-HttpAsyncClient/4.1.3 (Java/1.8.0_172)[\r][\n]"
DEBUG org.apache.http.wire - http-outgoing-0 >> "[\r][\n]"
DEBUG org.apache.http.wire - http-outgoing-0 >> "url_encoded=form_params&which_are=fine"
Everything seems fine, but for some reason, the client is prepending a line before the form body, with just \r\n
, which for some reason is tripping the server on the other end.
I don't control the server I'm sending the request to, I don't know if an empty line before the body conforms to the HTTP Spec, but my question is, is there any way to avoid it?
For completeness sake, the way I'm creating the request is as follows:
ApacheHttpClient.request<HttpResponse> {
method = <http://HttpMethod.Post|HttpMethod.Post>
url { takeFrom("<http://some.url/the/endpoint>") }
headers.append("Content-Type", ContentType.Application.FormUrlEncoded.contentSubtype)
this.body = body.formUrlEncode()
}
body is a List<Pair<String,String>>
and .formUrlEncode
is the extension method from ktor HttpUrlEncode.kte5l
08/10/2018, 2:10 PMAntero Duarte
08/10/2018, 2:16 PMAntero Duarte
08/10/2018, 2:17 PMe5l
08/10/2018, 2:17 PMAntero Duarte
08/10/2018, 2:17 PMAntero Duarte
08/10/2018, 2:17 PMAntero Duarte
08/10/2018, 2:17 PMAntero Duarte
08/10/2018, 2:19 PMDEBUG org.apache.http.wire - http-outgoing-0 << "HTTP/1.1 400 Bad Request[\r][\n]"
DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Type: application/json;charset=UTF-8[\r][\n]"
DEBUG org.apache.http.wire - http-outgoing-0 << "Vary: Origin[\r][\n]"
DEBUG org.apache.http.wire - http-outgoing-0 << "Date: Fri, 10 Aug 2018 13:53:42 GMT[\r][\n]"
DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Length: 259[\r][\n]"
DEBUG org.apache.http.wire - http-outgoing-0 << "[\r][\n]"
DEBUG org.apache.http.wire - http-outgoing-0 << "{"error":"invalid_request","error_description":"The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed","error_hint":"The POST body can not be empty.","status_code":400}"
Antero Duarte
08/10/2018, 2:23 PMe5l
08/10/2018, 2:23 PMContentType.Application.FormUrlEncoded.contentSubtype
e5l
08/10/2018, 2:23 PMContentType.Application.FormUrlEncoded.toString()
Antero Duarte
08/10/2018, 2:23 PMe5l
08/10/2018, 2:24 PMAntero Duarte
08/10/2018, 2:24 PMAntero Duarte
08/10/2018, 2:24 PMe5l
08/10/2018, 2:24 PMapplication/x-www-form-urlencoded
, but here is x-www-form-urlencoded
Antero Duarte
08/10/2018, 2:25 PMe5l
08/10/2018, 2:26 PMAntero Duarte
08/10/2018, 2:28 PMe5l
08/10/2018, 2:29 PMAntero Duarte
08/10/2018, 2:33 PMAntero Duarte
08/10/2018, 2:33 PMe5l
08/10/2018, 2:34 PMcy
08/13/2018, 8:26 AMfun StringValuesBuilder.append(name: String, value: HeaderValueWithParameters) {
append(name, value.toString())
}
cy
08/13/2018, 8:28 AMheaders.append(Header, ContentType.Something)
will be resolved to it