Skip to content

Commit

Permalink
fix(h5): 修复 h5 ContentType 重复设置的问题,fix #7972
Browse files Browse the repository at this point in the history
  • Loading branch information
Chen-jj committed Nov 5, 2020
1 parent 4f12112 commit 3dc07ac
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/taro-h5/src/api/request/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ function _request (options) {
url = generateRequestUrlWithParams(url, options.data)
} else if (typeof options.data === 'object') {
options.header = options.header || {}
options.header['Content-Type'] = options.header['Content-Type'] || options.header['content-type'] || 'application/json'
const contentType = options.header['Content-Type']

const keyOfContentType = Object.keys(options.header).find(item => item.toLowerCase() === 'content-type')
if (!keyOfContentType) {
options.header['Content-Type'] = 'application/json'
}
const contentType = options.header[keyOfContentType || 'Content-Type']

if (contentType.indexOf('application/json') >= 0) {
params.body = JSON.stringify(options.data)
Expand Down

0 comments on commit 3dc07ac

Please sign in to comment.