- 非標(biāo)準(zhǔn)HTTP方法如POST、PUT谭网、DELETE汪厨;
- 發(fā)送自定義請(qǐng)求頭,例如一個(gè)使用自定義請(qǐng)求頭 X-Custom-Header 的 POST 請(qǐng)求可能會(huì)觸發(fā)預(yù)檢索:
fetch('https://other-domain.com/api/data', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Custom-Header': 'custom value'
},
body: JSON.stringify({ data: 'example' })
});
- 請(qǐng)求體非
application/x-www-form-urlencoded
愉择、multipart/form-data
劫乱、text/plain
3.1. application/x-www-form-urlencoded:用于表單數(shù)據(jù)編碼,如果沒(méi)有指定enctype屬性锥涕,默認(rèn)就用此格式衷戈;
<form method="post" action="/login">
<input type="text" name="username" placeholder="用戶名">
<input type="password" name="password" placeholder="密碼">
<button type="submit">登錄</button>
</form>
數(shù)據(jù)結(jié)構(gòu):username=john&password=123456
3.2. multipart/form-data: 復(fù)雜數(shù)據(jù)結(jié)構(gòu),比如文件上傳等,
<form method="post" action="/upload" enctype="multipart/form-data">
<input type="text" name="description" placeholder="描述信息">
<input type="file" name="file">
<button type="submit">上傳</button>
</form>
3.3 text/plain:純文本格式的數(shù)據(jù)层坠,用于簡(jiǎn)單的文本數(shù)據(jù)提交,
<form method="post" action="/submit-text">
<textarea name="text-content"></textarea>
<button type="submit">提交</button>
</form>
服務(wù)器對(duì)于OPTIONS請(qǐng)求的相應(yīng)必須包含特定的CORS相關(guān)響應(yīng)頭殖妇,如Access-Control-Allow-Origin(允許訪問(wèn)的源)
、Access-Control-Allow-Methods(指定允許的HTTP方法)
破花、Access-Control-Allow-Headers(指定允許的請(qǐng)求頭)
等拉一,否則瀏覽器會(huì)阻止實(shí)際的POST請(qǐng)求。