/// <summary> /// Performs an HTTP DELETE on the URL and contains no body, returns the body as an XmlDocument if there is one /// </summary> public virtual Task <XmlDocument> Delete(HttpAsyncRequestFilter filter, XmlRequestResult result) { return(SimpleRequest("DELETE", filter, result, new string[] { })); }
private static async Task <XmlDocument> SimpleRequest(string method, HttpAsyncRequestFilter filter, XmlRequestResult result, params string[] parameters) { string absUri = UrlHelper.SafeToAbsoluteUri(result.uri); if (parameters.Length > 0) { FormData formData = new FormData(true, parameters); if (absUri.IndexOf('?') == -1) { absUri += "?" + formData.ToString(); } else { absUri += "&" + formData.ToString(); } } RedirectHelper.SimpleRequest simpleRequest = new RedirectHelper.SimpleRequest(method, filter); var response = await RedirectHelper.GetResponse(absUri, new RedirectHelper.RequestFactory(simpleRequest.Create)); try { result.uri = response.RequestMessage.RequestUri; result.responseHeaders = response.Headers; return(await ParseXmlResponse(response)); } finally { if (response != null) { response.Dispose(); } } }
/// <summary> /// Retrieve the specified URI, using the given filter, with the supplied parameters (if any). /// The parameters parameter should be an even number of strings, where each odd element is /// a param name and each following even element is the corresponding param value. For example, /// to retrieve http://www.vox.com/atom?svc=post&id=100, you would say: /// /// Get("http://www.vox.com/atom", "svc", "post", "id", "100"); /// /// If a param value is null or empty string, that param will not be included in the final URL /// (i.e. the corresponding param name will also be dropped). /// </summary> public virtual Task <XmlDocument> Get(HttpAsyncRequestFilter filter, XmlRequestResult result, params string[] parameters) { return(SimpleRequest("GET", filter, result, parameters)); }
protected virtual async Task <XmlDocument> Send(string method, string etag, HttpAsyncRequestFilter filter, string contentType, XmlDocument doc, string encoding, string filename, bool ignoreResponse, XmlRequestResult result) { if (!String.IsNullOrEmpty(filename)) { return(MultipartSend(method, etag, filter, contentType, doc, encoding, filename, ignoreResponse, result)); } string absUri = UrlHelper.SafeToAbsoluteUri(result.uri); Debug.WriteLine("XML Request to " + absUri + ":\r\n" + doc.GetXml()); SendFactory sf = new SendFactory(etag, method, filter, contentType, doc, encoding); var response = await RedirectHelper.GetResponse(absUri, new RedirectHelper.RequestFactory(sf.Create)); try { result.responseHeaders = response.Headers; result.uri = response.RequestMessage.RequestUri; if (ignoreResponse || response.StatusCode == Windows.Web.Http.HttpStatusCode.NoContent) { return(null); } else { XmlDocument xmlDocResponse = await ParseXmlResponse(response); return(xmlDocResponse); } } finally { if (response != null) { response.Dispose(); } } }
protected virtual XmlDocument MultipartSend(string method, string etag, HttpAsyncRequestFilter filter, string contentType, XmlDocument doc, string encoding, string filename, bool ignoreResponse, XmlRequestResult result) { throw new NotImplementedException(); }
/// <summary> /// Performs a multipart MIME HTTP POST with the specified XML document as the request body and filename as the payload. /// </summary> public Task <XmlDocument> Post(HttpAsyncRequestFilter filter, string contentType, XmlDocument doc, string encoding, string filename, XmlRequestResult result) { return(Send("POST", null, filter, contentType, doc, encoding, filename, false, result)); }
/// <summary> /// Performs an HTTP PUT with the specified XML document as the request body. /// </summary> public Task <XmlDocument> Put(string etag, HttpAsyncRequestFilter filter, string contentType, XmlDocument doc, string encoding, bool ignoreResponse, XmlRequestResult result) { return(Send("PUT", etag, filter, contentType, doc, encoding, null, ignoreResponse, result)); }