public void DeletePost(string blogId, string postId, bool publish) { Login(); FixupBlogId(ref blogId); Uri editUri = PostIdToPostUri(postId); try { RedirectHelper.SimpleRequest sr = new RedirectHelper.SimpleRequest("DELETE", new HttpRequestFilter(DeleteRequestFilter)); HttpWebResponse response = RedirectHelper.GetResponse(UrlHelper.SafeToAbsoluteUri(editUri), new RedirectHelper.RequestFactory(sr.Create)); response.Close(); } catch (Exception e) { if (e is WebException) { WebException we = (WebException)e; if (we.Response != null && we.Response is HttpWebResponse) { switch (((HttpWebResponse)we.Response).StatusCode) { case HttpStatusCode.NotFound: case HttpStatusCode.Gone: return; // these are acceptable responses to a DELETE } } } if (!AttemptDeletePostRecover(e, blogId, UrlHelper.SafeToAbsoluteUri(editUri), publish)) { throw; } } }
private static XmlDocument SimpleRequest(string method, ref Uri uri, HttpRequestFilter filter, out WebHeaderCollection responseHeaders, params string[] parameters) { string absUri = UrlHelper.SafeToAbsoluteUri(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); HttpWebResponse response = RedirectHelper.GetResponse(absUri, new RedirectHelper.RequestFactory(simpleRequest.Create)); try { uri = response.ResponseUri; responseHeaders = response.Headers; return ParseXmlResponse(response); } finally { if (response != null) response.Close(); } }
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(); } } }
public async Task DeletePost(string blogId, string postId, bool publish) { await Login(); FixupBlogId(ref blogId); Uri editUri = PostIdToPostUri(postId); try { RedirectHelper.SimpleRequest sr = new RedirectHelper.SimpleRequest("DELETE", new HttpAsyncRequestFilter(DeleteRequestFilter)); var response = await RedirectHelper.GetResponse(UrlHelper.SafeToAbsoluteUri(editUri), new RedirectHelper.RequestFactory(sr.Create)); if (!response.IsSuccessStatusCode) { if (response.StatusCode != Windows.Web.Http.HttpStatusCode.NotFound && response.StatusCode != Windows.Web.Http.HttpStatusCode.Gone) { throw new Exception(); } { return; } } } catch (Exception e) { if (!AttemptDeletePostRecover(e, blogId, UrlHelper.SafeToAbsoluteUri(editUri), publish)) { throw; } } }
private static XmlDocument SimpleRequest(string method, ref Uri uri, HttpRequestFilter filter, out WebHeaderCollection responseHeaders, params string[] parameters) { string absUri = UrlHelper.SafeToAbsoluteUri(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); HttpWebResponse response = RedirectHelper.GetResponse(absUri, new RedirectHelper.RequestFactory(simpleRequest.Create)); try { uri = response.ResponseUri; responseHeaders = response.Headers; return(ParseXmlResponse(response)); } finally { if (response != null) { response.Close(); } } }
public void DeletePost(string blogId, string postId, bool publish) { Login(); FixupBlogId(ref blogId); Uri editUri = PostIdToPostUri(postId); try { RedirectHelper.SimpleRequest sr = new RedirectHelper.SimpleRequest("DELETE", new HttpRequestFilter(DeleteRequestFilter)); HttpWebResponse response = RedirectHelper.GetResponse(UrlHelper.SafeToAbsoluteUri(editUri), new RedirectHelper.RequestFactory(sr.Create)); response.Close(); } catch (Exception e) { if (e is WebException) { WebException we = (WebException)e; if (we.Response != null && we.Response is HttpWebResponse) { switch (((HttpWebResponse)we.Response).StatusCode) { case HttpStatusCode.NotFound: case HttpStatusCode.Gone: return; // these are acceptable responses to a DELETE } } } if (!AttemptDeletePostRecover(e, blogId, UrlHelper.SafeToAbsoluteUri(editUri), publish)) throw; } }