How can I route http request through different host?
With python requests I can do following:
In nim when I try to do similar.
client.headers = newHttpHeaders({"Content-Type": "application/json", "Host": "other-url.com"})
let response = client.request(url, httpMethod = HttpPost, body = $body)
I'm getting error on the server.
Found multiple Host: headers
How can I override host when using httpclient library?
Hmmm, I get only one Host header locally with netcat:
POST / HTTP/1.1
Connection: Keep-Alive
content-length: 20
content-type: application/json
host: other-url.com
user-agent: Nim httpclient/1.4.4
{"data":"some text"}
Code:
import httpclient, json
let client = newHttpClient()
client.headers = newHttpHeaders({"Content-Type": "application/json",
"Host": "other-url.com"})
let body = %*{
"data": "some text"
}
let response = client.request("http://localhost:1234", httpMethod = HttpPost, body = $body)
echo response.status
Maybe something is wrong with header casing? Try with titleCase = true:
client.headers = newHttpHeaders({"Content-Type": "application/json", "Host": "other-url.com"}, titleCase = true)