小编Rap*_*phi的帖子

如何使用Angular $资源发送x-www-form-urlencoded数据?

我正在尝试向POST只接受x-www-form-urlencoded格式数据的服务器提交请求.

当我在Postman上测试时,它可以工作.例如,预览标题如下所示:

    POST /api/signin HTTP/1.1
    Host: myproj.herokuapp.com
    Cache-Control: no-cache
    Content-Type: application/x-www-form-urlencoded

    email=joe%40gmail.com&password=1234567
Run Code Online (Sandbox Code Playgroud)

但是,当我从我的应用程序运行它时,在Chrome控制台中查看的标题如下所示:

    Remote Address:10.10.10.250:80
    Request URL:http://myproj.herokuapp.com/api/signIn
    Request Method:POST
    Status Code:400 Bad Request
    Request Headersview source
    Accept:application/json, text/plain, */*
    Accept-Encoding:gzip, deflate
    Accept-Language:en-US,en;q=0.8
    Connection:keep-alive
    Content-Length:53
    Content-Type:application/x-www-form-urlencoded; charset=UTF-8
    Host:rapidit.herokuapp.com
    Origin:http://localhost
    Referer:http://localhost/rapid/v3/src/app/index/
    User-Agent:Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36
    Form Dataview parsed
    {"email":"joe@gmail.com","password":"1234567"}
Run Code Online (Sandbox Code Playgroud)

显然,它不是以正确的格式发送数据.

这就是我的Angular工厂中的样子(带有硬编码的登录数据):

var LoginResource = $resource("http://myproj.herokuapp.com/api/signIn", {}, {
         post: {
            method: "POST",
            isArray: false,
            headers: {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'}
        }
    });
    var loginUser = …
Run Code Online (Sandbox Code Playgroud)

forms post angularjs ngresource

6
推荐指数
2
解决办法
6685
查看次数

标签 统计

angularjs ×1

forms ×1

ngresource ×1

post ×1