高手都没空上来吧.我发了好几次,想散分都散不出去,郁闷中.结贴到c#给分.
我用c#做了个socket访问http服务器,但返回HTTP/1.1 400 Bad RequestContent-Type: text/htmlDate: Thu, 30 Nov 2006 15:16:33 GMTConnection: closeCon,已经困了我一个月了,哪位高手帮我解决我所有的分都给他
我的代码是
string hostName="www.eshuba.com";
IPHostEntry ipInfo=Dns.GetHostByName("www.eshuba.com");
IPAddress[] ipAddr=ipInfo.AddressList;
IPAddress ip=ipAddr[0];
int port=Int32.Parse("80");
IPEndPoint hostEP=new IPEndPoint(ip,port);
Socket socket=new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
try
{
socket.Connect(hostEP);
if (socket.Connected)Response.Write("ddddddddd");
}
catch(Exception se)
{
Response.Write("adfsafsdfds");
}
string sendStr="GET /down.asp?id=6794&no=1 HTTP/1.1\r\n
Accept: */*\r\n
Accept-Language: zh-cn\r\n
UA-CPU: x86\r\n
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; Maxthon; .NET CLR 1.1.4322; .NET CLR 2.0.50727)\r\n
Host: www.eshuba.com\r\n
Connection: Keep-Alive\r\n\r\n ";
///此外内容我是根据httplook得到.应该不会错.
byte[] bytesSendStr=new byte[1024];
bytesSendStr=Encoding.ASCII.GetBytes(sendStr);
bytesSendStr=Encoding.ASCII.GetBytes(sendStr);
try
{
//向主机发送请求
socket.Send(bytesSendStr,bytesSendStr.Length,0);
}
catch(Exception ce)
{
}
string recvStr="";
byte[] recvBytes=new byte[1024];
int bytes=0;
while(true)
{
bytes=socket.Receive(recvBytes,recvBytes.Length,0);
if(bytes<=0)
break;
recvStr+=Encoding.ASCII.GetString(recvBytes,0,bytes);
recvStr+=Encoding.ASCII.GetString(recvBytes,0,bytes);
}
tb_class.Text=recvStr;
////我最后得到的是tb_class.text = HTTP/1.1 400 Bad RequestContent-Type: text/htmlDate: Thu, 30 Nov 2006 15:16:33 GMTConnection: closeContent-Length: 39<h1>Bad Request (Invalid Hostname)</h1>
哪位大哥指点一下到底错在哪里,万分感激.
问题点数:10、回复次数:1Top
1 楼azurebz(撒哈拉大森林)回复于 2006-12-01 13:50:56 得分 0
帮顶Top





