scala – 如何在Akka-http 2.4.1中包含application / x-www-form
发布时间:2020-12-16 18:46:01 所属栏目:安全 来源:网络整理
导读:我正在使用Akka Http 2.4.1向twitter api发布https请求. 根据他们的documentation,我需要两个httpheaders.即,授权和ContentType. 引用他们的文档: 请求必须包含一个Content-Type标头,其值为application / x-www-form-urlencoded; charset = UTF-8. 这是我的
我正在使用Akka Http 2.4.1向twitter api发布https请求.
根据他们的documentation,我需要两个httpheaders.即,授权和ContentType. 引用他们的文档: 请求必须包含一个Content-Type标头,其值为application / x-www-form-urlencoded; charset = UTF-8. 这是我的代码: 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`)) 如何使用值application / x-www-form-urlencoded包含Content-Type标头;使用Akka-http 2.4.1包含charset = UTF-8? 解决方法
我想如果你将HttpRequest上的实体值更改为FormData,如下所示:
HttpRequest( uri = Uri("https://api.twitter.com/oauth2/token"),headers = List(authorization),entity = FormData("grant_type" -> "client_credentials").toEntity,protocol = HttpProtocols.`HTTP/1.1`) ) 然后你应该自动为你设置Content-Type到application / x-www-form-urlencoded; charset = UTF-8 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Firestore通过id在角度2上获取文档
- ng-inline-svg的Angular2异步测试问题
- AngularJS, Angular Material 与 Symfony 3 结合
- Angular 4.x template syntax & common directives
- Angular HttpClient 简单入门
- angularjs – 如何在登录后跟踪用户ID和Google Analytics并
- angular – 带有滤波器的ngrx选择器
- scala – 在jar中包含生成的资源(SBT)
- WebService开发流程(AAXIS、JAX-WS、XFire框架)
- bootstrap datetimepicker 格式化yyyymmdd时,无法读取yyyy