美文网首页
HTTP POST 三种请求方式 $http.post 、axi

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

作者: billzheng | 来源:发表于2020-09-23 11:06 被阅读0次
    // 注意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 、axi

          本文链接:https://www.haomeiwen.com/subject/chwnyktx.html