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

2020-09-23  本文已影响0人  billzheng
// 注意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);
                        }
                    });
                },

上一篇下一篇

猜你喜欢

热点阅读