I could not find a workaround for setting UseUnsafeHeaderParsing. I decided to remove the implementation of the HttpWebRequest class and use TcpClient instead. Using the TcpClient class will ignore any problems that may occur with HTTP headers - TcpClient does not even think about these terms.
In any case, using TcpClient, I can get data (including HTTP headers) from the proprietary web server that I mentioned in my initial post.
For the record, here is an example of retrieving data from a web server through TcpClient:
The code below essentially sends the client-side HTTP Header packet to the web server.
static string GetUrl(string hostAddress, int hostPort, string pathAndQueryString)
{
string response = string.Empty;
TcpClient socket = new TcpClient();
socket.Connect(hostAddress, hostPort);
NetworkStream ns = socket.GetStream();
StreamWriter sw = new StreamWriter(ns);
sw.WriteLine(string.Format("GET /{0} HTTP/1.1", pathAndQueryString));
sw.Flush();
string packet = string.Empty;
StreamReader sr = new StreamReader(ns);
do
{
packet = sr.ReadLine();
response += packet;
}
while (packet != null);
socket.Close();
return (response);
}
source
share