鍍金池/ 問(wèn)答/網(wǎng)絡(luò)安全  HTML/ fromdata傳遞數(shù)據(jù)

fromdata傳遞數(shù)據(jù)

請(qǐng)求中使用參數(shù)用form-data的形式:

  var content = new window.FormData();
  content.append("id", this.id);
  content.append("name", this.name);
      this.$http.post("test", content)
      .then(function (data) {
        if(data.status === 200 && data.ok === true){
          this.tipsmessage = '保存成功'
          this.success = true
        }else{
          this.tipsmessage = '保存失敗'
          this.success = false
        }
      })
      .catch(
          function (data) {
           console.log('請(qǐng)求出錯(cuò)')
        }
      )

頁(yè)面?zhèn)鬟f參數(shù)效果:
圖片描述

為什么傳遞格式不是這樣呢?

圖片描述


根據(jù)大家的回答,我做了修改:

this.$http({
      url: 'test',
      method: 'POST',
      data: content,
      headers: {
          'Content-Type': 'application/x-www-from-urlencoded'
      }
  })

結(jié)果:
圖片描述

content-type已經(jīng)修改成application/x-www-from-urlencoded這個(gè)格式了,但是沒(méi)有顯示傳遞的參數(shù),為什么呢?
圖片描述

回答
編輯回答
孤影

content-type 設(shè)置跟在數(shù)據(jù)后面

            //路徑   // 參數(shù) // 頭設(shè)置請(qǐng)求文本類型
    axios.post(url',params,{
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
    })

key:value格式 可以利用new URLSearchParams()方法 然后追加 append元素

json格式 那就 聲明拼接 對(duì)象值太多轉(zhuǎn)換JSON.stringify()

2018年3月6日 04:21
編輯回答
近義詞

this.$http.post("test", {id:xx})

你想key,value傳遞直接這樣就行了。不需要?jiǎng)?chuàng)建formdata對(duì)象。
如果你需要上傳文件,那就是選擇formData在chrome中的顯示效果。

2017年10月10日 15:12
編輯回答
焚音

你兩種content-type不同
你所說(shuō)的formdata是multipart/form-data,可以附帶文件,以流形式發(fā)送
你最后一張圖上列的請(qǐng)求方式是application/x-www-from-urlencoded,會(huì)將參數(shù)以kv形式發(fā)送,這個(gè)才是標(biāo)準(zhǔn)的表單類型

2017年9月11日 16:23
編輯回答
做不到

沒(méi)有怎么用過(guò)vue,但是看幫助文檔感覺(jué)應(yīng)該是這樣的,你可以試試

this.$http.post('test', {id: this.id, name: this.name}, {'emulateJSON': true})

https://github.com/pagekit/vu...

2018年9月17日 22:22