File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import { serializeParams } from '../utils'
4
4
5
5
function generateRequestUrlWithParams ( url , params ) {
6
6
params = typeof params === 'string' ? params : serializeParams ( params )
7
- url += ( ~ url . indexOf ( '?' ) ? '&' : '?' ) + ` ${ params } `
7
+ url += ( ~ url . indexOf ( '?' ) ? '&' : '?' ) + params
8
8
url = url . replace ( '?&' , '?' )
9
9
return url
10
10
}
@@ -45,6 +45,15 @@ export default function request (options) {
45
45
params . cache = options . cache || 'default'
46
46
if ( methodUpper === 'GET' || methodUpper === 'HEAD' ) {
47
47
url = generateRequestUrlWithParams ( url , options . data )
48
+ } else if ( methodUpper === 'POST' ) {
49
+ let contentType = options . header && ( options . header [ 'Content-Type' ] || options . header [ 'content-type' ] )
50
+ if ( contentType === 'application/json' ) {
51
+ params . body = JSON . stringify ( options . data )
52
+ } else if ( contentType === 'application/x-www-form-urlencoded' ) {
53
+ params . body = serializeParams ( options . data )
54
+ } else {
55
+ params . body = options . data
56
+ }
48
57
} else {
49
58
params . body = options . data
50
59
}
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ function serializeParams (params) {
45
45
return ''
46
46
}
47
47
return Object . keys ( params )
48
- . map ( item => ( `${ item } =${ enc ( params [ item ] ) } ` ) ) . join ( '&' )
48
+ . map ( key => ( `${ enc ( key ) } =${ enc ( params [ key ] ) } ` ) ) . join ( '&' )
49
49
}
50
50
51
51
export {
You can’t perform that action at this time.
0 commit comments