setContentType("application/x-www-form-urlencoded")播放框架2.0.x [英] setContentType("application/x-www-form-urlencoded") play framework 2.0.x
问题描述
我正在尝试调用Web服务,但是在play Framework 2.0.x中,我无法调用任何已编码的Web服务.
I am trying to invoke web service but in play framework 2.0.x i am unable to invoke any web service which is encoded.
我已经研究了代码:
public static Result wsAction() {
return async(
play.libs.WS.url(Play.application().configuration()
.getString("sms.service.url"))
.setContentType("application/x-www-form-urlencoded; charset=utf-8")
.post("param1=foo¶m2=bar").map(
new F.Function<WS.Response, Result>() {
public Result apply(WS.Response response) {
return ok(response.toString());
}
}
)
);
}
我已经在Play框架2.0.8上尝试了上述代码,但出现此错误:
i have tried the above code on play framework 2.0.8 but i am getting this error:
错误:找不到符号.setContentType("application/x-www-form-urlencoded; charset = utf-8")
error: cannot find symbol .setContentType("application/x-www-form-urlencoded; charset=utf-8")
有什么方法可以在播放框架2.0.8中设置内容类型. ?
is there any way to set content type in play framework 2.0.8. ?
谢谢
编辑:
这是我的代码:
Promise<WS.Response> result2 = WS.url("desired-url")
.setQueryParameter("sUsername","test")
.setQueryParameter("sPwd","hbl@1234")
.setQueryParameter("sMobileno","03332560744")
.setQueryParameter("sTransaction_id","asdfasdfasdfasdfasdf")
.setQueryParameter("sMessage","test")
.post("content");
WS.Response rs = result2.get();
它返回无效格式错误.并且我还使用 form-data 和相同的参数从REST Client中尝试了此操作,它还返回了相同的错误无效格式".但是当我尝试使用 x-www-form-urlencoded 时,它会返回所需的结果.但是在play 2.0中,我无法设置内容类型.
it returns me invalid format error. and i have also tried it from REST Client with form-data and with same parameters, it also returns me same error "Invalid Format". but when i tried it with x-www-form-urlencoded it returns the desired result. but in play 2.0 i cant set the the content Type.
谢谢
推荐答案
在play 2.0中,您可以做到
In play 2.0 you can do
response().setContentType("application/x-www-form-urlencoded; charset=utf-8");
return ok(response.toString());
这篇关于setContentType("application/x-www-form-urlencoded")播放框架2.0.x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!