public string Request(string resource, ERestMethod method, params string[] parameters) { _hasNewMessage = false; string request = CreateRequest(resource, method, parameters); _socket.Send(request); string response = string.Empty; switch (method) { case ERestMethod.GET: while (!_hasNewMessage) { DoNothing(); } response = _message; break; } _hasNewMessage = false; return(response); }
public void AsyncRequest(string resource, ERestMethod method, string[] parameters, Action <string> callback) { HttpWebRequest request = CreateRequest(resource, method, parameters); _callback = callback; request.BeginGetResponse(new AsyncCallback(GetResponceCallback), request); }
public string Request(string resource, ERestMethod method, params string[] parameters) { HttpWebRequest request = CreateRequest(resource, method, parameters); HttpWebResponse response = request.GetResponse() as HttpWebResponse; if (response.StatusCode != HttpStatusCode.OK) { string message = String.Format("Request failed. Received HTTP {0}", response.StatusCode); throw new ApplicationException(message); } StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); return(UnescapeString(reader.ReadToEnd())); }
public string CreateRequest(string resource, ERestMethod method, params string[] parameters) { string query = string.Empty; if (parameters != null && parameters.Length > 0) { string[] data = new string[parameters.Length / 2]; for (int i = 0; i < parameters.Length; i = i + 2) { data[i] = string.Format("{0}={1}", Uri.EscapeDataString(parameters[i]), Uri.EscapeUriString(parameters[i + 1])); } query = "&" + string.Join("&", data); } return(method + resource + query); }
protected HttpWebRequest CreateRequest(string resource, ERestMethod method, string[] parameters) { HttpWebRequest request = null; switch (method) { case ERestMethod.GET: string query = string.Empty; if (parameters != null && parameters.Length > 0) { string[] data = new string[parameters.Length / 2]; for (int i = 0; i < parameters.Length; i = i + 2) { data[i] = string.Format("{0}={1}", Uri.EscapeDataString(parameters[i]), Uri.EscapeUriString(parameters[i + 1])); } query = "?" + string.Join("&", data); } string url = _endPoint + "/" + resource + query; request = (HttpWebRequest)WebRequest.Create(Uri.EscapeUriString(url)); request.Method = WebRequestMethods.Http.Get; break; case ERestMethod.POST: throw new ApplicationException("TODO:"); break; } request.ContentLength = 0; request.ContentType = _contentType; request.Accept = _contentType; return(request); }
public void AsyncRequest(string resource, ERestMethod method, string[] parameters, Action <string> callback) { }