如何为.NET Compact Framework设置useUnsafeHeaderParsing [英] How To Set useUnsafeHeaderParsing For .NET Compact Framework

查看:152
本文介绍了如何为.NET Compact Framework设置useUnsafeHeaderParsing的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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).

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

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

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

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

对我而言,不幸的是,Compact中不包含System.Net.Configuration程序集框架。

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

CF中是否公开了类似的配置,允许我们以编程方式允许使用无效的标头?

Is there a similar configuration in CF that is exposed that allows us to programmatically allow for invalid headers?

推荐答案

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

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.

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

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 .

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

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

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

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

这篇关于如何为.NET Compact Framework设置useUnsafeHeaderParsing的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆