如何使用prestashop的post api使用react-native将产品添加到购物车中? 这是我在react-native中使用的代码
addtocart = () => {
console.log("adding to cart");
// const addtocarturl = "BFFRCL879WV8RDF35DY5MLVEMG19IKTJ@ec2-3-16-44-207.us-east-2.compute.amazonaws.com/api/carts?schema=blank";
// this.navigate.addtocarturl
// http://ec2-3-16-44-207.us-east-2.compute.amazonaws.com/api/carts?ws_key=BFFRCL879WV8RDF35DY5MLVEMG19IKTJ&schema=blank
fetch('http://ec2-3-16-44-207.us-east-2.compute.amazonaws.com/api/carts?ws_key=BFFRCL879WV8RDF35DY5MLVEMG19IKTJ&schema=blank',{
method: 'POST',headers: {
"async": true,"crossDomain": true,'accept': "*/*",'Content-Type': 'application/xml',// <-- Specifying the Content-Type
"Authorization": "Basic QkZGUknmODc5V1Y4UkRGMzVEWTVNTFZFTUcxOUlLVEo6","Host": "ec2-3-16-44-207.us-east-2.compute.amazonaws.com","Connection": "keep-alive","cache-control": "no-cache",},body: <prestashop>
<cart>
<id_address_delivery>10</id_address_delivery>
<id_address_invoice>10</id_address_invoice>
<id_currency >1</id_currency>
<id_customer>19</id_customer>
<id_lang >1</id_lang>
<delivery_option/>
<secure_key/>
<allow_seperated_package>0</allow_seperated_package>
<date_add>2015-06-23 14:45:08</date_add>
<date_upd>2015-06-23 14:45:08</date_upd>
<associations><cart_rows>
<cart_row>
<id_product>50</id_product>
<id_product_attribute >0</id_product_attribute>
<id_address_delivery >10</id_address_delivery>
<quantity>7</quantity>
</cart_row>
</cart_rows>
</associations>
</cart>
</prestashop>
})
.then((responseData) => { console.log(responseData) })
.catch((err) => { console.log(err); });
}
此发布方法用于将产品添加到购物车中。 它的抛出错误: 不变违规:不能用作本机方法参数