MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / send

Method send

packages/core/xhr/index.ts:225–265  ·  view source on GitHub ↗
(data?: any)

Source from the content-addressed store, hash-verified

223 }
224
225 public send(data?: any) {
226 this._errorFlag = false;
227 this._response = null;
228 this._responseTextReader = null;
229 this._headers = null;
230 this._status = null;
231
232 if (this._readyState !== this.OPENED || this._sendFlag) {
233 throw new Error("Failed to execute 'send' on 'XMLHttpRequest': " + "The object's state must be OPENED.");
234 }
235
236 if (isString(data) && this._options.method !== 'GET') {
237 //The Android Java HTTP lib throws an exception if we provide a
238 //a request body for GET requests, so we avoid doing that.
239 //Browser implementations silently ignore it as well.
240 this._options.content = data;
241 } else if (data instanceof FormData) {
242 this._options.content = (<FormData>data).toString();
243 } else if (data instanceof Blob) {
244 this.setRequestHeader('Content-Type', data.type);
245 this._options.content = Blob.InternalAccessor.getBuffer(data);
246 } else if (data instanceof ArrayBuffer) {
247 this._options.content = data;
248 }
249
250 this._sendFlag = true;
251
252 this.emitEvent('loadstart');
253
254 request(this._options)
255 .then((r) => {
256 if (!this._errorFlag && this._sendFlag) {
257 this._loadResponse(r);
258 }
259 })
260 .catch((e) => {
261 this._errorFlag = true;
262 this._sendFlag = false;
263 this._setRequestError('error', e);
264 });
265 }
266
267 public setRequestHeader(header: string, value: string) {
268 if (this._readyState !== this.OPENED || this._sendFlag) {

Calls 8

setRequestHeaderMethod · 0.95
emitEventMethod · 0.95
_loadResponseMethod · 0.95
_setRequestErrorMethod · 0.95
isStringFunction · 0.90
requestFunction · 0.90
toStringMethod · 0.45
getBufferMethod · 0.45

Tested by

no test coverage detected