如何为 .NET Compact Framework 设置 useUnsafeHeaderParsing

发布于 2024-10-14 04:43:59 字数 335 浏览 5 评论 0原文

在我的 Windows CE 6.0 应用程序中,我正在与返回错误标头信息的专有 Web 服务器设备进行通信(更具体地说,它不返回任何标头信息)。

我相信缺少标头信息是我的 HttpWebRequest 方法无法正常工作的原因。

我记得 .NET“常规”框架允许我们以编程方式配置 System.Net.Configuration 程序集以允许无效标头 (useUnsafeHeaderParsing)。

不幸的是,对我来说,System.Net.Configuration 程序集不包含在 Compact Framework 中。

CF 中是否有类似的配置可供我们以编程方式允许无效标头?

In my Windows CE 6.0 app, I am communicating with a proprietary web server device that is returning bad header information (more specifically, it's returning NO header information).

I believe this lack of header information is the reason why my HttpWebRequest methods are not working properly.

I recall that the .NET "regular" Framework allows for us to programmatically configure the System.Net.Configuration assembly to allow for 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 is exposed that allows us to programmatically allow for invalid headers?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

要走干脆点 2024-10-21 04:43:59

我无法找到设置 UseUnsafeHeaderParsing 的解决方法。我决定删除 HttpWebRequest 类的实现并改用 TcpClient。使用 TcpClient 类将忽略 HTTP 标头可能存在的任何问题 - TcpClient 甚至不会考虑这些问题。

无论如何,使用 TcpClient,我可以从我在原始帖子中提到的专有 Web 服务器获取数据(包括 HTTP 标头)。

作为记录,下面是如何通过 TcpClient 从 Web 服务器检索数据的示例:

下面的代码本质上是将客户端 HTTP 标头数据包发送到 Web 服务器。

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);
}

I was unable to find a work-around for setting the UseUnsafeHeaderParsing. I decided to remove the implementation of the HttpWebRequest class and use the TcpClient instead. Using the TcpClient class will ignore any problems that may exist with the HTTP Headers - the TcpClient doesn't even think in those terms.

Anyway, using the TcpClient I am able to get the data (including the HTTP Headers) from the proprietary web server that I mentioned in my original post .

For the record, here is a sample of how to retrieve data from a web server via the TcpClient:

The code below is essentially sending a client side HTTP Header packet to a 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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文