Add parameters to URL (querystring)

SomeResponseClass response = WebRequestBuilder<SomeResponseClass>
	.ForUrl("https://www.acme.com/services/data/url")
	.AddParameter("param1").WithValue("abc")
	.AddParameter("param2").WithValue(123)
	.Submit()
	.Get();
Use IFormatProvider for parameter value

NumberFormatInfo nfi = (NumberFormatInfo)CultureInfo.CurrentCulture.NumberFormat.Clone();
nfi.NumberDecimalSeparator = ".";

DateTimeFormatInfo dfi = (DateTimeFormatInfo)CultureInfo.CurrentCulture.DateTimeFormat.Clone();
dfi.ShortTimePattern = "yyyyMMdd";

SomeResponseClass response = WebRequestBuilder<SomeResponseClass>
	.ForUrl("https://www.acme.com/services/data/url")
	.AddParameter("param1").WithValue("abc")
	.AddParameter("date").WithValue(DateTime.Now, dfi)
	.AddParameter("param2").WithValue(123.4, nfi)
	.Submit()
	.Get();
Use options to setup Request object
SomeResponseClass response = WebRequestBuilder<SomeResponseClass>
	.ForUrl("https://www.acme.com/services/data/url")
	.WithOptions
		.ContentType("text/plain")
		.UserAgent("IExplorer")
		.Proxy(myProxy)
	.EndOptions()
	.AddParameter("param1").WithValue("abc")
	.Submit()
	.Get();
Send a DELETE
SomeResponseClass response = WebRequestBuilder<SomeResponseClass>
	.ForUrl("https://www.acme.com/services/data/url")
	.AddParameter("lang").WithValue("de")
	.Submit()
	.Delete();
Add custom fields to request header
NameValueCollection headers = new NameValueCollection()
{
	{ "APPLICATION_KEY", "abc123" }
};

SomeResponseClass response = WebRequestBuilder<SomeResponseClass>
	.ForUrl("https://www.acme.com/services/data/url")
	.WithOptions.Headers(headers).EndOptions()
	.Submit()
	.Delete();

Last edited Jan 18, 2013 at 9:41 PM by tatis, version 5

Comments

No comments yet.