/* * Send GET request * */ private void RequestGET(HttpEngineState state, string serviceId, string secret, string dir) { _user = serviceId; _password = secret; _dir = dir; _url = HOST_URI + dir; _uri = new Uri(_url); _isPOST = false; var request = (HttpWebRequest)WebRequest.Create(_uri); request.Method = "GET"; request.UseDefaultCredentials = false; RequestState customRequestState = new RequestState(); customRequestState.Request = request; customRequestState.HttpEngineState = state; // If we've got a recent Auth header, re-use it! if (!string.IsNullOrEmpty(_cnonce) && DateTime.Now.Subtract(_cnonceDate).TotalHours < 1.0) { request.Headers[HttpRequestHeader.Authorization] = GetDigestHeader(dir); } request.BeginGetResponse(RequestCompleted, customRequestState); }
/* * Make POST request * */ private void RequestPOST(HttpEngineState state, string serviceId, string secret, string dir, byte[] parameters) { _user = serviceId; _password = secret; _dir = dir; _url = HOST_URI + dir; _uri = new Uri(_url); _isPOST = true; var request = (HttpWebRequest)WebRequest.Create(_uri); request.UseDefaultCredentials = false; request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.Headers[HttpRequestHeader.ContentLength] = parameters.Length.ToString(); // If we've got a recent Auth header, re-use it if (!string.IsNullOrEmpty(_cnonce) && DateTime.Now.Subtract(_cnonceDate).TotalHours < 1.0) { request.Headers[HttpRequestHeader.Authorization] = GetDigestHeader(dir); } // Put the request into the state object so it can be passed around RequestState customRequestState = new RequestState(); customRequestState.Request = request; customRequestState.PostByteArray = parameters; customRequestState.HttpEngineState = state; customRequestState.Dir = dir; customRequestState.Secret = secret; customRequestState.ServiceId = serviceId; request.BeginGetRequestStream(GetRequestStreamCallback, customRequestState); }