angularjs - 在Groovy应用程序中接收Json数据

标签 angularjs rest http grails groovy

我正在开发这个应用程序,它将是一个前端,它将使用其他应用程序中的数据,但首先,它将凭据发布到已经在生产环境中运行的另一个应用程序中,并且在接受凭据后,应在用户登录后重定向到该应用程序。

问题来了。我已经测试过将数据发送到其他应用程序的数据正在接收

     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/";
        });
    }
}

我在同伴上让他的PC上运行了另一个应用程序的情况下进行了此测试。

从概念上讲,我可能做错了什么。我知道通过在$ window.location.href = url + params中发送参数可以工作,但是我不希望凭证在url中传播。我知道我可以对它们进行编码,但是如果可能的话,让我们尝试其他尝试。

最佳答案

这里的问题是提交使用了错误的Content-Type。服务器将在体内查找POST-vars。正确使用的值是:

Content-Type: application/json

(而不是application/x-www-form-urlencoded;charset=utf8)

关于angularjs - 在Groovy应用程序中接收Json数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50397701/

相关文章:

javascript - AmChart 标签被砍掉

javascript - Angular 交互 2 种不同类型的数组 - 单个 ng-repeat 中的线性数组和 json 数组

javascript - Angular Js 初学者 Ajax 调用

javascript - HTML 按钮刷新页面而不是将数据发送到数据库

python - 无法修改 django rest framework base.html 文件

php - 如何使用 PHP 将文件 POST 到 REST 服务器而不将文件写入磁盘?

C++ Winsock编程,没有收到HTTP协议(protocol)的响应

http - 现在不需要 Expires header 了吗?

json - 如何在 Glassfish 4 上创建一个简单的 JSON Jersey 2.x RESTful Web 服务?

php - URL 不显示文件名或扩展名,怎么办? (PHP)