非法响应集管Scala喷淋管道
当我试图通过管道发送来自Scala spray的请求时,出现以下错误非法响应集管Scala喷淋管道,scala,spray,spray-client,Scala,Spray,Spray Client,当我试图通过管道发送来自Scala spray的请求时,出现以下错误 [play-akka.actor.default-dispatcher-14] INFO application - Pipelining chain request [WARN] [03/19/2015 11:08:49.115] [application-akka.actor.default-dispatcher-2] [akka://application/user/IO-HTTP/group-0/0] Illegal
[play-akka.actor.default-dispatcher-14] INFO application - Pipelining chain request
[WARN] [03/19/2015 11:08:49.115] [application-akka.actor.default-dispatcher-2] [akka://application/user/IO-HTTP/group-0/0] Illegal response header: Illegal 'Access-Control-Allow-Origin' header: Unexpected end of input, expected $timesAccess$minusControl$minusAllow$minusOrigin (line 1, pos 1):
^
下面是我构建请求的地方:
val pipeline =
addCredentials(BasicHttpCredentials("API_KEY",
"API_SECRET")) ~> sendReceive
val response: Future[HttpResponse] = pipeline(Post(api,notification))
Logger.info("Pipelining chain request")
response
我对访问控制允许源代码不太了解。我是否需要向该请求添加某种类型的头以使其正常工作 错误本身意味着未正确解析标头(请参阅)。这个标题是非常新的,允许。正常访问控制允许原点的示例(来自):
我猜你可能会使用一些旧版本的spray,它不支持多个来源,或者可能与。无论如何,只有在请求中指定了Origin
头(这意味着CORS启动)时,服务器才会返回带有此头的响应,因此应该通过从中删除Origin
头来解决问题
更新:这是您使用的chain.com API的一个bug。如果未指定Origin
标题,则它们会将访问控制允许Origin:
(空字符串)返回给您,因此不可解析:
这是我试图调用的api,它是chain.com
api的一个bug-它们向您发送Access Control Allow Origin
,并指定值“”(空字符串,不可解析)rif noOrigin
头,可能的解决方法是实际指定此原点
标题。我将用什么填充原点标题?在处理响应或发送请求时,我会填充这个吗?在发送请求时(我添加了示例)。您可以使用任何有效的URI(如htttp://example.com
)-这并不重要,因为这是一种变通方法。因此在我的示例中,我将使用类似于addHeader(“Origin”,“mydomain.com”)
"Access-Control-Allow-Origin" in {
"Access-Control-Allow-Origin: *" =!= `Access-Control-Allow-Origin`(AllOrigins)
"Access-Control-Allow-Origin: null" =!= `Access-Control-Allow-Origin`(SomeOrigins(Nil))
"Access-Control-Allow-Origin: http://spray.io" =!= `Access-Control-Allow-Origin`(SomeOrigins(Seq("http://spray.io")))
}
> curl -v https://api.chain.com/v2/notifications -X POST
> POST /v2/notifications HTTP/1.1
> User-Agent: curl/7.41.0
> Host: api.chain.com
> Accept: */*
>
< HTTP/1.1 401 Unauthorized
< Access-Control-Allow-Credentials: true
< Access-Control-Allow-Methods: GET,POST,PATCH,PUT,DELETE,OPTIONS,HEAD
< Access-Control-Allow-Origin:
< Content-Type: text/plain; charset=utf-8
< Date: Sun, 22 Mar 2015 01:38:07 GMT
< Strict-Transport-Security: max-age=25920000; includeSubDomains
< Vary: Accept-Encoding
< Www-Authenticate: Basic realm="chain-api"
< X-Content-Type-Options: nosniff
< X-Frame-Options: DENY
< X-Xss-Protection: 1
< Content-Length: 47
< Connection: keep-alive
<
{"code":"CH004","message":"Must authenticate"}
>curl -v https://api.chain.com/v2/notifications -X POST -H "Origin: http://google.com"
> POST /v2/notifications HTTP/1.1
> User-Agent: curl/7.41.0
> Host: api.chain.com
> Accept: */*
> Origin: http://google.com
< HTTP/1.1 401 Unauthorized
< Access-Control-Allow-Credentials: true
< Access-Control-Allow-Methods: GET,POST,PATCH,PUT,DELETE,OPTIONS,HEAD
< Access-Control-Allow-Origin: http://google.com
< Content-Type: text/plain; charset=utf-8
< Date: Sun, 22 Mar 2015 01:39:10 GMT
< Strict-Transport-Security: max-age=25920000; includeSubDomains
< Vary: Accept-Encoding
< Www-Authenticate: Basic realm="chain-api"
< X-Content-Type-Options: nosniff
< X-Frame-Options: DENY
< X-Xss-Protection: 1
< Content-Length: 47
< Connection: keep-alive