如何用url形式的编码主体发出请求?

时间:2018-07-18 06:14:31

标签: javascript react-native ecmascript-6 fetch

我有一个后发请求,我需要发送x-www-form-urlencoded keyValue对参数,而content-type应该是x-www-form-urlencoded。在这里,我将Json作为主体发送。我只是想知道如何在体内发送此消息并在购物车函数中调用它

  

url:http://something/carts/ {cart_id}

     

邮递员表单正文= {id}:{value}

   static post(url, headers, body, resolve, reject) {
   fetch(`${this.data}${url}`, {
   headers: headers,
   method: 'POST',
   body: JSON.stringify(body)
 })
      .then((resp) => {
        resolve(resp.json());
      })
      .catch(err => reject(err))
    }

   static Cart(id, product_id) {
   return new Promise((resolve, reject) => {
   this.post(`/carts/${cart_id}${product_id}`, {
  //Does this url correct.

   "Content-Type": "application/x-www-form-urlencoded",
   "X-Authorization": this.authorization_key
        }, resolve, reject)
    })
 }

0 个答案:

没有答案