public void AsyncGet(string path, Dictionary<string, string> qparams, OnAsyncResult callback) { string complete_uri = ConcatPaths(m_uri, path); complete_uri += BuildQueryString(qparams); HttpWebRequest request = (HttpWebRequest) HttpWebRequest.Create(complete_uri); request.Accept = "application/json"; request.Method = "GET"; AddAuthorizationHeader(request); request.BeginGetResponse(delegate (IAsyncResult result){ string body = ""; try{ HttpWebRequest _request = (HttpWebRequest) result.AsyncState; HttpWebResponse response = (HttpWebResponse) _request.EndGetResponse(result); using(StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8)){ body = sr.ReadToEnd(); } callback((int)response.StatusCode, body); } catch(WebException e){ // TODO: Elaborate exceptions callback((int)((HttpWebResponse)e.Response).StatusCode, ((HttpWebResponse)e.Response).StatusDescription); } catch{ callback(400, null); } }, request); }
public void AsyncGet(string path, Dictionary <string, string> qparams, OnAsyncResult callback) { string complete_uri = ConcatPaths(m_uri, path); complete_uri += BuildQueryString(qparams); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(complete_uri); request.Accept = "application/json"; request.Method = "GET"; AddAuthorizationHeader(request); request.BeginGetResponse(delegate(IAsyncResult result){ string body = ""; try{ HttpWebRequest _request = (HttpWebRequest)result.AsyncState; HttpWebResponse response = (HttpWebResponse)_request.EndGetResponse(result); using (StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8)){ body = sr.ReadToEnd(); } callback((int)response.StatusCode, body); } catch (WebException e) { // TODO: Elaborate exceptions callback((int)((HttpWebResponse)e.Response).StatusCode, ((HttpWebResponse)e.Response).StatusDescription); } catch { callback(400, null); } }, request); }