diff --git a/packages/taro-h5/src/api/request/index.js b/packages/taro-h5/src/api/request/index.js index f67a79bce87c..3893c01e1ecb 100644 --- a/packages/taro-h5/src/api/request/index.js +++ b/packages/taro-h5/src/api/request/index.js @@ -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)