/** * HTTP 통신 클라이언트 클래스 * * @author kimjihwan */ function HttpClient() { this.m_objHttpFactory; this.m_objHttpRequest; }; HttpClient.prototype.status = function () { if (4 == this.m_objHttpRequest.readyState) { return this.m_objHttpRequest.status; } else { return null; } }; HttpClient.prototype.post = function (strURL, objData, bAsync, strContentsType, strEncoding, bMutipart, strBoundary) { return this._sendHttpRequest("POST", strURL, objData, bAsync, strContentsType, strEncoding, bMutipart, strBoundary); }; HttpClient.prototype.get = function (strURL, bAsync, strContentsType, strEncoding) { return this._sendHttpRequest("GET", strURL, null, bAsync, strContentsType, strEncoding, false, null); }; HttpClient.prototype.put = function (strURL, objData, bAsync, strContentsType, strEncoding) { return this._sendHttpRequest("PUT", strURL, objData, bAsync, strContentsType, strEncoding, false, null); }; HttpClient.prototype.deleteMethod = function (strURL, objData, bAsync, strContentsType, strEncoding) { return this._sendHttpRequest("DELETE", strURL, objData, bAsync, strContentsType, strEncoding, false, null); }; HttpClient.prototype._sendHttpRequest = function (strMethod, strURL, objData, bAsync, strContentsType, strEncoding, bMutipart, strBoundary) { if (null == bAsync) { bAsync = false; } if (null == strContentsType || strContentsType.isEmpty()) { strContentsType = "application/x-www-form-urlencoded"; } if (null == strEncoding || strEncoding.isEmpty()) { strEncoding = "UTF-8"; } this.m_objHttpRequest = this._makeHttpRequest(); if (bAsync) { this.m_objHttpRequest.onreadystatechange = HttpClient.handleASyncHttpResponse; } this.m_objHttpRequest.open(strMethod, strURL, bAsync); if (bMutipart) { this.m_objHttpRequest.setRequestHeader("Content-Type", strContentsType + "; boundary=" + strBoundary); } else { this.m_objHttpRequest.setRequestHeader("Content-Type", strContentsType + ";charset=UTF-8"); } this.m_objHttpRequest.send(objData); if (!bAsync) { return this._handleSyncHttpResponse(strURL); } }; /** * 동기 모드일때 답신을 처리한다. * @return */ HttpClient.prototype._handleSyncHttpResponse = function (strURL) { if (4 == this.m_objHttpRequest.readyState) { if (200 == this.m_objHttpRequest.status) { if("text/html" == this.m_objHttpRequest.getResponseHeader("Content-Type")) { // TODO redirect } else { if (null != window.console) { if (!is_smartphone) { if (null != window.console) { console.log(" Connect URL : " + strURL); console.log(" Connect STATUS : " + this.m_objHttpRequest.status); console.log(" Connect STATUS TEXT : " + this.m_objHttpRequest.statusText); } } else { if (null != window.console) { console.log(this.m_objHttpRequest.status + "," + this.m_objHttpRequest.statusText + "," + strURL); } } } return this.m_objHttpRequest.responseText; } } else { if (!is_smartphone) { if (null != window.console) { console.log(" Connect URL : " + strURL); console.log(" Connect STATUS : " + this.m_objHttpRequest.status); console.log(" Connect STATUS TEXT : " + this.m_objHttpRequest.statusText); } } else { if (null != window.console) { console.log(this.m_objHttpRequest.status + "," + this.m_objHttpRequest.statusText + "," + strURL); } } return null; } } }; HttpClient.prototype._makeHttpRequest = function () { if (null != this.m_objHttpFactory) { return this.m_objHttpFactory(); } for (var i=0; i