[英]React Native Post Request via Fetch throws Network Request Failed
[英]Network request failed when fetch post with multipart form data
我試過關注https://stackoverflow.com/a/40714217/9957948和https://stackoverflow.com/a/35206069/9957948沒有成功。 我仍然收到Network request failed
。
這是我的 cURL 請求有效:
curl -X POST "url" -H "Content-Type: multipart/form-data; boundary=--CUSTOM" -H "Content-Length: 237" -d $'----CUSTOM\nContent-Disposition: form-data; name="fileToUpload"; filename="t006"\nContent-Type: application/octet-stream\n\nset shiftwidth=4\nset autoindent\n\n----CUSTOM\nContent-Disposition: form-data; name="submit"\n\nUpload Image\n----CUSTOM--\n'
這是我嘗試將其轉換為的內容,它返回Network request failed.
uploadFile(){
const formData = new FormData()
formData.append('blob', new Blob(['set shiftwidth=4\nset autoindent\n']), 't006')
fetch('url', {
method: 'POST',
body: formData
})
.then(data => {
console.log(data)
})
.catch(error => {
console.log('error:' + error.message);
})
是否需要Content-Length
或正文Content-Type: application/octet-stream
?
我對這一切都很陌生,所以任何幫助都將不勝感激。 謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.