使用x-www-formurl-encoded的角度POST不起作用

问题描述 投票:1回答:1

这是我用来发布的方法

let body2 =`client_id=C123&grant_type=authorization_code&redirect_uri=http://redirecturl.com&code=abc-123`

let header = new HttpHeaders({
      "Content-Type": "application/x-www-form-urlencoded",
      "client_id": "C123"
})
let options = { headers: header }

this.http.post<any>(http://posturl.com, body2, options)

响应为Invalid Client

但是当我使用ajax进行相同的调用时,我得到了想要的响应

$.ajax({
            url: 'http://posturl.com',
            type: 'post',
            data: {
                "client_id": "C123",
                "grant_type": "authorization_code",
                "redirect_uri": "http://redirecturl.com",
                "code": "abc-123"
            },
            headers: {
                "Content-Type": "application/x-www-form-urlencoded",
                "client_id": "C123"
            },
            done: function (data) {
                console.log(data);
            }

现在我不知道问题出在哪里。

jquery angular typescript post
1个回答
0
投票
尝试

let body2 = { client_id: "C123", grant_type: "authorization_code", redirect_uri: "http://redirecturl.com", code: "abc-123" } var formData = new FormData(); for ( var key in body2) { formData.append(key, item[key]); } this.http.post("http://posturl.com", formData).subscribe();

© www.soinside.com 2019 - 2024. All rights reserved.