|
@@ -133,7 +133,7 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget{
|
133
|
133
|
|
134
|
134
|
if(this._readyState !== XMLHttpRequest.OPENED)
|
135
|
135
|
throw 'InvalidStateError : XMLHttpRequest is not opened yet.'
|
136
|
|
-
|
|
136
|
+ let promise = Promise.resolve()
|
137
|
137
|
this._sendFlag = true
|
138
|
138
|
log.verbose('XMLHttpRequest send ', body)
|
139
|
139
|
let {_method, _url, _headers } = this
|
|
@@ -141,26 +141,37 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget{
|
141
|
141
|
log.verbose(typeof body, body instanceof FormData)
|
142
|
142
|
|
143
|
143
|
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
|
+ })
|
145
|
150
|
}
|
146
|
151
|
else if(typeof body === 'object') {
|
147
|
152
|
body = JSON.stringify(body)
|
|
153
|
+ promise = Promise.resolve()
|
148
|
154
|
}
|
149
|
|
- else
|
|
155
|
+ else {
|
150
|
156
|
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
|
+ })
|
164
|
175
|
}
|
165
|
176
|
|
166
|
177
|
overrideMimeType(mime:string) {
|
|
@@ -311,6 +322,7 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget{
|
311
|
322
|
})
|
312
|
323
|
break;
|
313
|
324
|
default :
|
|
325
|
+ console.log(resp, resp.text())
|
314
|
326
|
this._responseText = resp.text()
|
315
|
327
|
this._response = this.responseText
|
316
|
328
|
responseDataReady()
|