鍍金池/ 問答/HTML/ vue axios post請求發(fā)送圖片base64編碼給后臺報錯HTTP 錯誤

vue axios post請求發(fā)送圖片base64編碼給后臺報錯HTTP 錯誤 414

使用axios上傳base64數(shù)據(jù)給后臺,請求 報錯http414

圖片描述

圖片只有8kb,并不大

onChange(file, fileName){
    const self = this;
    console.log(file);
    var reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onloadend = function() {
        self.form.imgSrc = this.result;
//        Vue.set(this.form,'imgSrc',)
    };
    console.log("1:"+self.form.imgSrc);
},

//上傳圖片
uploadImg(){
    console.log("2:"+this.form.imgSrc);
    const url ='http://**************';
    this.$axios({
        method: 'post',
        url:url,
        params: {
            is_iso:1,
            img_base64:this.form.imgSrc,
            type:1
        }
    }).then((res)=>{
        console.log("3:"+this.form.imgSrc);
        if(res.data.errCode==0){
            this.$alert(res.data.retData.msg);
            const imgSucUrl = res.data.retData.img_info.img_url;
            this.form.imgSucUrl = imgSucUrl;
            console.log(res.data)
        }else if(res.data.errCode==1){
            this.$alert(res.data.retData.msg);
            console.log(res.data);
        }
    });
},

這是我的上傳圖片的請求代碼

回答
編輯回答
檸檬藍

‘request URI too large’說明你的url長度太大了。

你使用的POST方式,為什么不把圖片數(shù)據(jù)放到請求體中呢?放到url末尾作為參數(shù)不合適吧。

建議你把圖片數(shù)據(jù)放到data中。

2018年8月16日 01:36
編輯回答
別瞎鬧
axios.post('api',base64Data)
2017年3月27日 19:47