Sto usando Akka Http 2.4.1 per pubblicare una richiesta https su twitter api.Come includere application/x-www-form-urlencoded HttpHeader in Akka-http 2.4.1?
In base al loro documentation, ho bisogno di due httpheaders. Vale a dire, Autorizzazione e ContentType.
per citare i loro documenti:
La richiesta deve includere un header Content-Type con il valore di application/x-www-form-urlencoded; charset = UTF-8.
Ecco il mio codice:
val authorization = Authorization(BasicHttpCredentials(key, secret))
/*
This header is removed from the request with the following explanation!
"Explicitly set HTTP header 'Content-Type: application/x-www-form-urlencoded;' is ignored, illegal RawHeader"
*/
val contentType = RawHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8")
Http().singleRequest(
HttpRequest(
uri = Uri("https://api.twitter.com/oauth2/token"),
method = HttpMethods.POST,
headers = List(authorization, contentType),
entity = HttpEntity(`text/plain(UTF-8)`, "grant_type=client_credentials"),
protocol = HttpProtocols.`HTTP/1.1`))
Come posso includere l'intestazione Content-Type
con il valore application/x-www-form-urlencoded;charset=UTF-8
utilizzando Akka-http 2.4.1?
Content-Type sarà impostata automaticamente in base al tipo di entità inclusa nella richiesta. Nel tuo caso stai impostando il tipo di contenuto delle tue entità http su 'text/plain (UTF-8)'. – cmbaxter
Grazie per la spiegazione aggiuntiva. Utile! – rodoherty1