public void CreatesSubmitableConnection() { string html = "<form action='/search'><input name='q'></form>"; Document doc = Dcsoup.Parse(html, "http://example.com/"); doc.Select("[name=q]").Attr("value", "jsoup"); FormElement form = ((FormElement)doc.Select("form").First); var client = new System.Net.Http.HttpClient(); var message = form.SubmitAsync(client).Result; Assert.AreEqual(System.Net.Http.HttpMethod.Get, message.RequestMessage.Method); Assert.AreEqual("http://example.com/search?q=jsoup", message.RequestMessage.RequestUri.ToString()); // request url has a query parameter string. doc.Select("form").Attr("method", "post"); var message2 = form.SubmitAsync(client).Result; Assert.AreEqual(System.Net.Http.HttpMethod.Post, message2.RequestMessage.Method); }
public void ActionWithNoValue() { string html = "<form><input name='q'></form>"; Document doc = Dcsoup.Parse(html, "http://example.com/"); FormElement form = ((FormElement)doc.Select("form").First); var client = new System.Net.Http.HttpClient(); var message = form.SubmitAsync(client).Result; Assert.AreEqual("http://example.com/?q=", message.RequestMessage.RequestUri.ToString()); // request url has a query parameter string. }
public void ActionWithNoBaseUri() { string html = "<form><input name='q'></form>"; Document doc = Dcsoup.Parse(html); FormElement form = ((FormElement)doc.Select("form").First); var ex = Assert.Throws(typeof(ArgumentException), () => { var client = new System.Net.Http.HttpClient(); var message = form.SubmitAsync(client).Result; }); Assert.AreEqual("Could not determine a form action URL for submit. Ensure you set a base URI when parsing.", ex.Message); }