Ich verwende Akka Http 2.4.1, um eine https Anfrage an die Twitter API zu senden.Wie kann man application/x-www-form-urlencoded HttpHeader in Akka-http 2.4.1 einbinden?
Entsprechend ihrer documentation benötige ich zwei httpheaders. Nämlich, Autorisierung und ContentType.
ihre Dokumente zu zitieren:
Der Antrag mit dem Wert von application/x-www-form-urlencoded einen Content-Type-Header enthält; charset = UTF-8.
Hier ist mein Code:
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`))
Wie kann ich die Content-Type
Header mit dem Wert application/x-www-form-urlencoded;charset=UTF-8
mit Akka-http 2.4.1 enthalten?
Content-Type wird eingestellt eingestellt werden automatisch basierend auf dem Entitätstyp, der in der Anfrage enthalten ist. In Ihrem Fall setzen Sie den Inhaltstyp http-Entitäten auf 'text/plain (UTF-8)'. – cmbaxter
Danke für die zusätzliche Erklärung. Hilfreich! – rodoherty1