/// <summary> /// Gets the direct response of a direct HTTP request. /// </summary> /// <param name="webRequest">The web request.</param> /// <returns>The response to the web request.</returns> /// <exception cref="ProtocolException">Thrown on network or protocol errors.</exception> protected override DirectWebResponse GetDirectResponse(HttpWebRequest webRequest) { DirectWebResponse response = this.WebRequestHandler.GetResponse(webRequest, DirectWebRequestOptions.AcceptAllHttpResponses); // Filter the responses to the allowable set of HTTP status codes. if (response.Status != HttpStatusCode.OK && response.Status != HttpStatusCode.BadRequest) { if (Logger.IsErrorEnabled) { using (var reader = new StreamReader(response.ResponseStream)) { Logger.ErrorFormat( "Unexpected HTTP status code {0} {1} received in direct response:{2}{3}", (int)response.Status, response.Status, Environment.NewLine, reader.ReadToEnd()); } } // Call dispose before throwing since we're not including the response in the // exception we're throwing. response.Dispose(); ErrorUtilities.ThrowProtocol(OpenIdStrings.UnexpectedHttpStatusCode, (int)response.Status, response.Status); } return(response); }
/// <summary> /// Gets the protocol message that may be in the given HTTP response. /// </summary> /// <param name="response">The response that is anticipated to contain an protocol message.</param> /// <returns> /// The deserialized message parts, if found. Null otherwise. /// </returns> protected override IDictionary <string, string> ReadFromResponseInternal(DirectWebResponse response) { ErrorUtilities.VerifyArgumentNotNull(response, "response"); string body = response.GetResponseReader().ReadToEnd(); return(HttpUtility.ParseQueryString(body).ToDictionary()); }
/// <summary> /// Gets the protocol message that may be in the given HTTP response. /// </summary> /// <param name="response">The response that is anticipated to contain an protocol message.</param> /// <returns> /// The deserialized message parts, if found. Null otherwise. /// </returns> /// <exception cref="ProtocolException">Thrown when the response is not valid.</exception> protected override IDictionary <string, string> ReadFromResponseInternal(DirectWebResponse response) { if (response == null) { throw new ArgumentNullException("response"); } try { return(this.keyValueForm.GetDictionary(response.ResponseStream)); } catch (FormatException ex) { throw ErrorUtilities.Wrap(ex, ex.Message); } }