我用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>
哪位大哥指点一下到底错在哪里,万分感激.
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>
哪位大哥指点一下到底错在哪里,万分感激.
解决方案 »
- 请问sql table为什么不能有多个primary key
- [道歉帖]上次做错事了 说错话了 道个歉 请个教
- C#2005中继承DataGridViewTextBoxColumn后加入自定义属性问题?
- 怎么查找DataGri中行中的DatagridTextBox.
- 求C#写ORACLE数据库的方法(急)100分不够再加
- JScript问题
- 如何跟踪C#调用的外部命令执行情况呢?
- WPF DataGrid ColumnHeaderHeight 的问题
- 如何用正则表达式提取字符串?
- 2个问题
- csdn里到底有没有高手啊,我这个菜鸟遇到的问题怎么没人能解答啊?
- 请问CSDN论坛小助手是怎么实现的呢?
HTTP/1.1 404 Not FoundContent-Length: 1308Content-Type: text/htmlServer: Microsoft-IIS/6.0Date: Fri, 01 Dec 2006 06:03:02 GMTConnection: close<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><HTML><HEAD><TITLE>无法找到该页</TITLE><META HTTP-EQUIV="Content-Type" Content="text/html; charset=GB2312"><STYLE type="text/css"> BODY { font: 9pt/12pt 宋体 } H1 { font: 12pt/15pt 宋体 } H2 { font: 9pt/12pt 宋体 } A:link { color: red } A:visited { color: maroon }</STYLE></HEAD><BODY><TABLE width=500 border=0 cellspacing=10><TR><TD><h1>无法找到该页</h1>您正在搜索的页面可能已经删除、更名或暂时不可用。<hr><p>请尝试以下操作:</p><ul><li>确保浏览器的地址栏中显示的网站地址的拼写和格式正确无误。</li><li>如果通过单击链接而到达了该网页,请与网站管理员联系,通知他们该链接的格式不正确。</li><li>单击<a href="javascript:history.back(1)">后退</a>按钮尝试另一个链接。</li></ul><h2>HTTP 错误 404 - 文件或目录未找到。<br>Internet 信息服?(IIS)</h2><hr><p>技术信息(为技术支持人员提供)</p><ul><li>转到 <a href="http://go.microsoft.com/fwlink/?linkid=8180">Microsoft 产品支持服务</a>并搜索包括“HTTP”和“404”的标题。</li><li>打开“IIS 帮助”(可在 IIS 管理器 (inetmgr) 中访问),然后搜索标题为“网站设置”、“常规管理任务”和“关于自定义错误消息”的主题。</li></ul></TD></TR><