/// <summary> /// Create a new <see cref="PlatformHttpRequest" />. /// </summary> /// <param name="uri">The URL to access. This cannot be null, empty or whitespace.</param> /// <param name="method">The HTTP method to use. Defaults to <see cref="PlatformHttpMethod.Get" /> if /// omitted.</param> /// <param name="userAccount">The user account.</param> /// <param name="doNotAuthenticate">Flag indicating whether automatic authentication should occur or it should stay anonymous</param> /// <exception cref="System.ArgumentNullException">uri</exception> /// <exception cref="System.InvalidOperationException">RequestContext not set. Use [RunAsDefaultTenant].</exception> /// <exception cref="ArgumentNullException">uri</exception> public PlatformHttpRequest(string uri, PlatformHttpMethod method = PlatformHttpMethod.Get, UserAccount userAccount = null, bool doNotAuthenticate = false) { if (string.IsNullOrWhiteSpace(uri)) { throw new ArgumentNullException("uri"); } if (!doNotAuthenticate && !RequestContext.IsSet) { throw new InvalidOperationException("RequestContext not set. Use [RunAsDefaultTenant]."); } var host = GetHost( ); var requestUri = string.Concat(host, "/SpApi/", uri); // Ignore broken certs, because PMs, etc, want to run this on machines that have bad certs if (!_certificatesIgnored) { _certificatesIgnored = true; ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; } HttpWebRequest = WebRequest.CreateHttp(requestUri); HttpWebRequest.Method = method.ToString( ).ToUpperInvariant( ); HttpWebRequest.Headers ["Tz"] = "Australia/Sydney"; if (doNotAuthenticate) { return; } AddFakeLoginTokens(HttpWebRequest, host, userAccount); }
/// <summary> /// Create a new <see cref="PlatformHttpRequest" />. /// </summary> /// <param name="uri">The URL to access. This cannot be null, empty or whitespace.</param> /// <param name="method">The HTTP method to use. Defaults to <see cref="PlatformHttpMethod.Get" /> if /// omitted.</param> /// <param name="userAccount">The user account.</param> /// <param name="doNotAuthenticate">Flag indicating whether automatic authentication should occur or it should stay anonymous</param> /// <param name="isFullUri">The Uri is complete including protocol, machine name.</param> /// <exception cref="System.ArgumentNullException">uri</exception> /// <exception cref="System.InvalidOperationException">RequestContext not set. Use [RunAsDefaultTenant].</exception> /// <exception cref="ArgumentNullException">uri</exception> public PlatformHttpRequest(string uri, PlatformHttpMethod method = PlatformHttpMethod.Get, UserAccount userAccount = null, bool doNotAuthenticate = false, bool isFullUri = false) { if (string.IsNullOrWhiteSpace(uri)) { throw new ArgumentNullException("uri"); } if (!doNotAuthenticate && !RequestContext.IsSet) { throw new InvalidOperationException("RequestContext not set. Use [RunAsDefaultTenant]."); } var host = GetHost(); string requestUri = isFullUri ? uri : string.Concat(host, "/SpApi/", uri); HttpWebRequest = WebRequest.CreateHttp(requestUri); HttpWebRequest.Method = method.ToString().ToUpperInvariant(); HttpWebRequest.Headers["Tz"] = "Australia/Sydney"; if (doNotAuthenticate) { return; } AddFakeLoginTokens(HttpWebRequest, host, userAccount); }