/// <summary> /// Create a request to initialize a request. /// </summary> /// <returns> /// An HttpWebRequest configured to initialize a request. /// </returns> /// <param name="contentLength">Length of the content to be uploaded (in bytes).</param> /// <param name="contentType">Content type of the content to be uploaded.</param> private HttpWebRequest CreateInitializeRequest(long contentLength, string contentType) { HttpWebRequestBuilder builder = new HttpWebRequestBuilder() { BaseUri = new Uri(this.baseUri), Method = this.httpMethod, Path = this.path, HttpRequestFactory = this.RequestFactory, }; builder.AddParameter(RequestParameterType.Query, "uploadType", "resumable"); SetAllPropertyValues(builder); var request = builder.GetWebRequest(); request.Headers.Add(PayloadContentTypeHeader, contentType); request.Headers.Add(PayloadContentLengthHeader, contentLength.ToString()); if (this.Authenticator != null) { Authenticator.ApplyAuthenticationToRequest(request); } string bodyText = this.Serializer.Serialize(this.Body); byte[] body = Encoding.UTF8.GetBytes(bodyText); request.ContentType = JsonMimeType; request.ContentLength = body.Length; var requestBodyStream = request.GetRequestStream(); requestBodyStream.Write(body, 0, body.Length); return(request); }
public void TestBasicWebRequest() { var builder = new HttpWebRequestBuilder() { BaseUri = UriFactory.Create("http://www.example.com/") }; var wr = builder.GetWebRequest(); Assert.That(wr.Method, Is.EqualTo("GET")); Assert.That(wr.RequestUri.AbsoluteUri, Is.EqualTo("http://www.example.com/")); }
public void TestPathParameterWithUrlEncode() { var builder = new HttpWebRequestBuilder() { BaseUri = UriFactory.Create("http://www.example.com/"), Path = "test/{id}", }; builder.AddParameter(RequestParameterType.Path, "id", " %va/ue"); var wr = builder.GetWebRequest(); Assert.That(wr.Method, Is.EqualTo("GET")); Assert.That(wr.RequestUri.AbsoluteUri, Is.EqualTo("http://www.example.com/test/%20%25va%2Fue")); }
public void TestSingleQueryParameter() { var builder = new HttpWebRequestBuilder() { BaseUri = UriFactory.Create("http://www.example.com/"), }; builder.AddParameter(RequestParameterType.Query, "testQueryParam", "testValue"); var wr = builder.GetWebRequest(); Assert.That(wr.Method, Is.EqualTo("GET")); Assert.That(wr.RequestUri.AbsoluteUri, Is.EqualTo("http://www.example.com/?testQueryParam=testValue")); }
public void TestMultipleQueryParameters() { var builder = new HttpWebRequestBuilder() { BaseUri = UriFactory.Create("http://www.example.com/"), }; builder.AddParameter(RequestParameterType.Query, "q", "value1"); builder.AddParameter(RequestParameterType.Query, "q", "value2"); var wr = builder.GetWebRequest(); Assert.That(wr.Method, Is.EqualTo("GET")); Assert.That(wr.RequestUri.AbsoluteUri, Is.EqualTo("http://www.example.com/?q=value1&q=value2")); }