/// <summary> /// A helper function to make the HTTP request. /// </summary> /// <param name="uri">The address for the request.</param> /// <returns>The response code and associated response from the server.</returns> private async Task <Tuple <HttpStatusCode, String> > MakeRequestFor(String uri) { HttpWebRequest req = HttpWebRequest.Create(uri) as HttpWebRequest; req.Method = "GET"; req.Credentials = creds; return(await AsyncHTTPRequest.MakeAsyncRequest(req)); }
public void TestMakingRequest() { Tuple <HttpStatusCode, String> response = AsyncHTTPRequest.MakeAsyncRequest("http://www.google.com").Result; Assert.IsNotNull(response); Assert.IsTrue(response.Item1 == HttpStatusCode.OK); Assert.IsTrue(response.Item2.Length > 0); }
public void TestPostingKeyVar() { byte[] data = System.Text.Encoding.UTF8.GetBytes("key1=value1&key2=value2&key3=value3"); String result = "key: 'key1' value: 'value1'\nkey: 'key2' value: 'value2'\nkey: 'key3' value: 'value3'"; request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = data.Length; Tuple <HttpStatusCode, String> response = AsyncHTTPRequest.MakeAsyncRequest(request, data).Result; Assert.IsNotNull(response); Assert.IsTrue(response.Item1 == HttpStatusCode.OK); Assert.IsTrue(response.Item2.Contains(result)); }
public void TestPostingBody() { String body = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras iaculis pulvinar tellus, ac porta dolor dignissim sit amet. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed iaculis pulvinar dolor, id dictum ipsum ultricies ac. Vestibulum eget facilisis mi. Maecenas sed eros elit. Duis commodo cursus mauris et mattis. Cras pharetra quam tortor. Donec id odio lacus, pellentesque molestie sapien. Donec et urna dolor, et pellentesque tortor. Curabitur mattis, neque id mollis mollis, dui magna lacinia turpis, at placerat nunc ipsum eu ipsum. Quisque sit amet sem at libero scelerisque cursus."; byte[] data = System.Text.Encoding.UTF8.GetBytes(body); request.Method = "POST"; request.ContentType = "text/plain"; request.ContentLength = data.Length; Tuple <HttpStatusCode, String> response = AsyncHTTPRequest.MakeAsyncRequest(request, data).Result; Assert.IsNotNull(response); Assert.IsTrue(response.Item1 == HttpStatusCode.OK); Assert.IsTrue(response.Item2.Contains(body)); }