How to configure useUnsafeHeaderParsing for .NET Compact Framework

In my Windows CE 6.0 application, I am communicating with a proprietary web server device that returns bad header information (more specifically, it returns NO header information).

I believe that the lack of header information is the reason that my HttpWebRequest methods do not work correctly.

I remember that the .NET "regular" Framework allows us to programmatically configure the System.Net.Configuration assembly to allow invalid headers (useUnsafeHeaderParsing).

Unfortunately, for me, the System.Net.Configuration assembly is not included in the Compact Framework.

Is there a similar configuration in CF that displays, which allows us to programmatically resolve invalid headers?

+3
source share
1 answer

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;

//Get the stream that will be used to send/receive data
TcpClient socket = new TcpClient();
socket.Connect(hostAddress, hostPort);
NetworkStream ns = socket.GetStream();    

//Write the HTTP Header info to the stream
StreamWriter sw = new StreamWriter(ns);
sw.WriteLine(string.Format("GET /{0} HTTP/1.1", pathAndQueryString));
sw.Flush();

//Save the data that lives in the stream (Ha! sounds like an activist!)
string packet = string.Empty;
StreamReader sr = new StreamReader(ns);
do
{
packet = sr.ReadLine();
response += packet;
}
while (packet != null);

socket.Close();

return (response);
}
+7
source

Source: https://habr.com/ru/post/1788086/


All Articles