在 groovy 应用中接收 Json 数据
Receiving Json data in groovy app
我正在开发这个应用程序,它将作为一个前端使用来自其他应用程序的数据,但首先,它将向另一个已经 运行 在生产中的应用程序发布凭据,并且在接受凭据后应该在用户登录的情况下重定向到该应用程序。
问题来了。我已经测试过将数据发送到其他应用程序正在接收数据
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接收到的正在打印的参数。
我现在将添加我的 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/";
});
}
}
我正在和一个在他的 PC 上安装了另一个应用 运行 的同伴一起做这个测试。
从概念上讲,我可能做错了什么。我知道通过在 $window.location.href = url+params 中发送参数将起作用,但我不希望凭据在 url 中传输。我知道我可以对它们进行编码,但如果可能的话,让我们在放弃之前尝试其他方法。
这里的问题是使用了错误的 Content-Type
进行提交。服务器将在正文中查找 POST-vars。使用的正确值是:
Content-Type: application/json
(而不是 application/x-www-form-urlencoded;charset=utf8
)
我正在开发这个应用程序,它将作为一个前端使用来自其他应用程序的数据,但首先,它将向另一个已经 运行 在生产中的应用程序发布凭据,并且在接受凭据后应该在用户登录的情况下重定向到该应用程序。
问题来了。我已经测试过将数据发送到其他应用程序正在接收数据
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接收到的正在打印的参数。
我现在将添加我的 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/";
});
}
}
我正在和一个在他的 PC 上安装了另一个应用 运行 的同伴一起做这个测试。
从概念上讲,我可能做错了什么。我知道通过在 $window.location.href = url+params 中发送参数将起作用,但我不希望凭据在 url 中传输。我知道我可以对它们进行编码,但如果可能的话,让我们在放弃之前尝试其他方法。
这里的问题是使用了错误的 Content-Type
进行提交。服务器将在正文中查找 POST-vars。使用的正确值是:
Content-Type: application/json
(而不是 application/x-www-form-urlencoded;charset=utf8
)