public HttpResponse(string response) { this.Content = response; string[] result = Regex.Split(response, @"^\r\n", RegexOptions.Multiline); this.HeaderContent = result.FirstOrDefault(); this.Body = result.LastOrDefault(); this.Headers = HttpCommon.GetHeaders(this.HeaderContent); ParseStatus(); if (this.Headers["Location"] != null) { this.RedirectUrl = this.Headers["Location"]; } }
private string GetRequestContent(HttpMethod method, string data = null) { StringBuilder request = new StringBuilder(); request.Append(method.ToString()).Append(HttpCommon.SPACE).Append(RequestUri.PathAndQuery).Append(HttpCommon.SPACE).Append("HTTP/1.0").Append(HttpCommon.LINEBREAK); request.Append("Host").Append(HttpCommon.COLON).Append(HttpCommon.SPACE).Append(RequestUri.DnsSafeHost).Append(HttpCommon.LINEBREAK); request.Append(HttpCommon.GetHeaders(this.Headers)); if (method == HttpMethod.POST) { request.Append("Content-Type").Append(HttpCommon.COLON).Append("application/x-www-form-urlencoded").Append(HttpCommon.LINEBREAK); request.Append("Content-Length").Append(HttpCommon.COLON).Append(data.Length.ToString()).Append(HttpCommon.LINEBREAK); request.Append(HttpCommon.LINEBREAK); request.Append(data); } return(request.ToString()); }