[英]Json As Writeable Scala Play Framework
I am trying to take an http
request and send it to another service. 我正在尝试接受http
请求并将其发送到另一服务。 I want to use the json sent from the first POST
and send it on to the next service. 我想使用从第一个POST
发送的json并将其发送到下一个服务。 The problem I am having is turning the POST
data as json and put it into a new POST
but it is not Play's type Writeable
. 我遇到的问题是将POST
数据转换为json并将其放入新的POST
但它不是Play类型的Writeable
。
Here is the code: 这是代码:
def postProxyParse(proxyUrl: String) = Action.async { request =>
var url = buildUrl(request.uri)
val data = request.body.asJson
if(url ==""){
badRequest(null, "Url Not matching proxy possibilities")
}
WS.url(url).post(data).map { response =>
Ok(response.body)
}
}
The Error I am getting is Cannot write an instance of Option[play.api.libs.json.JsValue] to HTTP response. Try to define a Writeable[Option[play.api.libs.json.JsValue]]
我遇到的错误是Cannot write an instance of Option[play.api.libs.json.JsValue] to HTTP response. Try to define a Writeable[Option[play.api.libs.json.JsValue]]
Cannot write an instance of Option[play.api.libs.json.JsValue] to HTTP response. Try to define a Writeable[Option[play.api.libs.json.JsValue]]
Hi so the point of this was to create a proxy service to redirect post requests with a specific url. 嗨,所以这一点是创建一个代理服务来重定向具有特定URL的帖子请求。 The answer to this problem is: 这个问题的答案是:
def postProxyParse(proxyUrl: String) = Action.async { request =>
val url = buildUrl(request.uri)
var data = Json.parse(request.body.asText.get);
if(url ==""){
badRequest(null, "Url Not matching proxy possibilities")
}
WS.url(url).withHeaders( "Accept" -> "application/json",
"Cookie" -> ("sessionId=" + request.cookies.apply("sessionId").value)).post(data).map { response =>
Ok(data)
}
}
The full code for a scala proxy service is here Scala代理服务的完整代码在这里
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.