HTTP POST 三种请求方式 $http.post 、axios.post 、$.ajax

// 注意json数据要字符化后才能请求,JSON.stringify(json_data);

                CDNforbidstream: function() {
                    let json_data = {
                        "appid": this.appid,
                        "timestamp": this.timestamp,
                        "nonce": this.nonce,
                        "seq": 1,
                        "stream_alias": "zegotest-842504334-streamid_1600771133428",
                        "signature": this.signature
                    };
                    //发送 post 请求, Vue.js Ajax(vue-resource)
                    this.$http.post('https://media-apigateway-test.zego.im/api/cdn/forbidstream', JSON.stringify(json_data), {
                        emulateJSON: true
                    }).then(function(suc) {
                        console.warn(suc);
                    }, function(res) {
                        console.log(res.status);
                    });
                },

                CDNforbidstream2: function() {
                    let json_data = {
                        "appid": this.appid,
                        "timestamp": this.timestamp,
                        "nonce": this.nonce,
                        "seq": 1,
                        "stream_alias": "zegotest-842504334-streamid_1600771133428",
                        "signature": this.signature
                    };
                    //发送 post 请求, Vue.js Ajax(axios)
                    axios.post('https://media-apigateway-test.zego.im/api/cdn/forbidstream', JSON.stringify(json_data))
                        .then(function(response) {
                            console.log(response);
                            console.log('data>>',response.data);
                        })
                        .catch(function(error) {
                            console.log(error);
                        });
                },

                CDNforbidstream3: function() {
                    let json_data = {
                        "appid": this.appid,
                        "timestamp": this.timestamp,
                        "nonce": this.nonce,
                        "seq": 1,
                        "stream_alias": "zegotest-842504334-streamid_1600771133428",
                        "signature": this.signature
                    };
                    // 发送 post 请求, jQuery ajax() 方法
                    $.ajax({ 
                        url: "https://media-apigateway-test.zego.im/api/cdn/forbidstream",
                        type: 'post',
                        data: JSON.stringify(json_data),
                        success: function(data) {
                            console.warn(data);
                        },
                        error: function(err) {
                            console.error(err);
                        }
                    });
                },

你可能感兴趣的:(HTTP POST 三种请求方式 $http.post 、axios.post 、$.ajax)