feat: complate deploy feature

backup
MiaoWoo 2020-05-08 00:50:30 +08:00
parent e0ab8a5a7b
commit 2beca068a4
2 changed files with 5 additions and 4 deletions

View File

@ -27,7 +27,7 @@ function request(config: RequestConfig) {
for (const header in config.headers) { for (const header in config.headers) {
xhr.setRequestHeader(header, config.headers[header]); xhr.setRequestHeader(header, config.headers[header]);
} }
xhr.send(config.data); xhr.send(typeof config.data === "string" ? config.data : JSON.stringify(config.data));
if ((xhr.getResponseHeader("Content-Type") + '').indexOf('application/json') != -1) { if ((xhr.getResponseHeader("Content-Type") + '').indexOf('application/json') != -1) {
xhr.responseType = "json" xhr.responseType = "json"
} }

View File

@ -151,6 +151,8 @@ export class XMLHttpRequest {
this._mimeType = mimeType; this._mimeType = mimeType;
} }
open(method: RequestMethod, url: string, async: boolean = true, user?: string, password?: string) { open(method: RequestMethod, url: string, async: boolean = true, user?: string, password?: string) {
if (this._readyState !== ReadyState.UNSENT) { throw new Error(`Error Status ${this._readyState}!`) }
this._method = method; this._method = method;
this._url = url; this._url = url;
this._async = async; this._async = async;
@ -195,7 +197,7 @@ export class XMLHttpRequest {
this.onloadstart(); this.onloadstart();
if (body) { if (body) {
let bodyType = Object.prototype.toString.call(body); let bodyType = Object.prototype.toString.call(body);
if (bodyType !== '[object String]') { throw new Error(`body(${bodyType}) must be string!`) } if (typeof body !== "string") { throw new Error(`body(${bodyType}) must be string!`) }
var out = this._connection.getOutputStream(); var out = this._connection.getOutputStream();
out.write(new JavaString(body).getBytes(UTF_8)); out.write(new JavaString(body).getBytes(UTF_8));
out.flush(); out.flush();
@ -204,7 +206,6 @@ export class XMLHttpRequest {
this.setReadyState(ReadyState.LOADING); this.setReadyState(ReadyState.LOADING);
this._status = this._connection.getResponseCode(); this._status = this._connection.getResponseCode();
this._statusText = this._connection.getResponseMessage(); this._statusText = this._connection.getResponseMessage();
this.setResponseHeaders(this._connection.getHeaderFields());
if (this._status >= 0 && this._status < 300) { if (this._status >= 0 && this._status < 300) {
this._response = this.readOutput(this._connection.getInputStream()); this._response = this.readOutput(this._connection.getInputStream());
} else if (this._status >= 300 && this._status < 400) { } else if (this._status >= 300 && this._status < 400) {
@ -212,6 +213,7 @@ export class XMLHttpRequest {
} else { } else {
this._response = this.readOutput(this._connection.getErrorStream()); this._response = this.readOutput(this._connection.getErrorStream());
} }
this.setResponseHeaders(this._connection.getHeaderFields());
this.onloadend(); this.onloadend();
} catch (ex) { } catch (ex) {
if (ex instanceof SocketTimeoutException && this.ontimeout) { if (ex instanceof SocketTimeoutException && this.ontimeout) {
@ -227,7 +229,6 @@ export class XMLHttpRequest {
} }
private setResponseHeaders(header: any) { private setResponseHeaders(header: any) {
this._responseHeaders = {};
header.forEach((key: string | number, value: string | any[]) => { header.forEach((key: string | number, value: string | any[]) => {
this._responseHeaders[key] = value[value.length - 1] this._responseHeaders[key] = value[value.length - 1]
}); });