Angularjs 在groovy应用程序中接收Json数据
我正在开发这个应用程序,它将是一个前端,使用来自其他应用程序的数据,但首先,它将向已经在生产中运行的另一个应用程序发布凭据,并且在接受凭据后,它应该在用户登录的情况下重定向到该应用程序 问题来了。我已经测试过将数据发送到其他应用程序,数据正在作为Angularjs 在groovy应用程序中接收Json数据,angularjs,rest,http,grails,groovy,Angularjs,Rest,Http,Grails,Groovy,我正在开发这个应用程序,它将是一个前端,使用来自其他应用程序的数据,但首先,它将向已经在生产中运行的另一个应用程序发布凭据,并且在接受凭据后,它应该在用户登录的情况下重定向到该应用程序 问题来了。我已经测试过将数据发送到其他应用程序,数据正在作为 params: [{"j_username":"username","j_password":"password","instance":"http:8080/TERA/authAuto"}:, action:authAuto, contro
params: [{"j_username":"username","j_password":"password","instance":"http:8080/TERA/authAuto"}:, action:authAuto, controller:login]
username: null
Prueba: null
我试图接受这一切,但没有成功
request.JSON.j_username
params.j_username
params["j_username"]
params:实际上是groovy收到的正在打印的params
现在我将添加我的angularJs代码
vm.login = function(){
$http({
method: 'POST',
url: "http://t0002161750:8080/TERA/authAuto",
data: {j_username: vm.user.username, j_password: vm.user.password, instance: "http://t0002161750:8080/TERA/authAuto"},
headers:{
'Content-Type': 'application/x-www-form-urlencoded;charset=utf8'
}
}).success(function(response){
$window.location.href = "http://t0002161750:8080/TERA/";
});
}
}
我和一个同伴一起做这个测试,在他的电脑上运行另一个应用程序
从概念上讲,我可能做错了什么。我知道通过在$window.location.href=url+params中发送参数将起作用,但我不希望凭证在url中移动。我知道我可以对它们进行编码,但如果可能的话,让我们在放弃之前尝试其他方法 这里的问题是在提交时使用了错误的
内容类型。服务器将在主体中查找POST变量。使用的正确值为:
Content-Type: application/json
(而不是application/x-www-form-urlencoded;charset=utf8
)您是否尝试过内容类型:application/json
?@cfrick TY!!!就这么简单,像我一样工作expected@AndiFB如果cfrick的回答解决了你的问题,那么对他的评论投赞成票可能是一种良好的因果报应。