UseUnsafeHeaderParsingを設定するための回避策が見つかりませんでした。私は、HttpWebRequestクラスの実装を削除し、代わりにTcpClientを使用することにしました。 TcpClientクラスを使用すると、HTTPヘッダーに存在する可能性のある問題はすべて無視されます。つまり、TcpClientはこれらの用語でも考えません。
とにかく、TcpClientを使用して、元の投稿に記載した独自のWebサーバーからデータ(HTTPヘッダーを含む)を取得できます。レコードの
は、ここれるtcpClientを介してウェブサーバからデータを取得する方法のサンプルです:
以下のコードは、基本的にWebサーバにクライアント側HTTPヘッダパケットを送信しています。
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);
}
出典
2011-02-01 21:38:37
Jed
+1質問に戻って答えます。 – ctacke
私に多くの時間を節約してくれてありがとう! –