@@ -133,34 +133,45 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget{
133133
134134 if ( this . _readyState !== XMLHttpRequest . OPENED )
135135 throw 'InvalidStateError : XMLHttpRequest is not opened yet.'
136-
136+ let promise = Promise . resolve ( )
137137 this . _sendFlag = true
138138 log . verbose ( 'XMLHttpRequest send ' , body )
139139 let { _method, _url, _headers } = this
140140 log . verbose ( 'sending request with args' , _method , _url , _headers , body )
141141 log . verbose ( typeof body , body instanceof FormData )
142142
143143 if ( body instanceof Blob ) {
144- body = RNFetchBlob . wrap ( body . getRNFetchBlobRef ( ) )
144+ promise = new Promise ( ( resolve , reject ) => {
145+ body . onCreated ( ( blob ) => {
146+ body = RNFetchBlob . wrap ( body . getRNFetchBlobRef ( ) )
147+ resolve ( )
148+ } )
149+ } )
145150 }
146151 else if ( typeof body === 'object' ) {
147152 body = JSON . stringify ( body )
153+ promise = Promise . resolve ( )
148154 }
149- else
155+ else {
150156 body = body ? body . toString ( ) : body
151- this . _task = RNFetchBlob
152- . config ( {
153- auto : true ,
154- timeout : this . _timeout ,
155- binaryContentTypes : XMLHttpRequest . binaryContentTypes
156- } )
157- . fetch ( _method , _url , _headers , body )
158- this . _task
159- . stateChange ( this . _headerReceived . bind ( this ) )
160- . uploadProgress ( this . _uploadProgressEvent . bind ( this ) )
161- . progress ( this . _progressEvent . bind ( this ) )
162- . catch ( this . _onError . bind ( this ) )
163- . then ( this . _onDone . bind ( this ) )
157+ promise = Promise . resolve ( )
158+ }
159+
160+ promise . then ( ( ) => {
161+ this . _task = RNFetchBlob
162+ . config ( {
163+ auto : true ,
164+ timeout : this . _timeout ,
165+ binaryContentTypes : XMLHttpRequest . binaryContentTypes
166+ } )
167+ . fetch ( _method , _url , _headers , body )
168+ this . _task
169+ . stateChange ( this . _headerReceived . bind ( this ) )
170+ . uploadProgress ( this . _uploadProgressEvent . bind ( this ) )
171+ . progress ( this . _progressEvent . bind ( this ) )
172+ . catch ( this . _onError . bind ( this ) )
173+ . then ( this . _onDone . bind ( this ) )
174+ } )
164175 }
165176
166177 overrideMimeType ( mime :string ) {
@@ -311,6 +322,7 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget{
311322 } )
312323 break ;
313324 default :
325+ console . log ( resp , resp . text ( ) )
314326 this . _responseText = resp . text ( )
315327 this . _response = this . responseText
316328 responseDataReady ( )
0 commit comments