private String ConnectionHost(String HostName,String Url,int Port,String PostData)
{
//解析域名
IPHostEntry IPHostInfo = Dns.GetHostEntry(HostName);
//获取域名IP地址
IPAddress IP = IPHostInfo.AddressList[0];
IPEndPoint Connection = new IPEndPoint(IP, Port);
Socket HttpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
HttpSocket.ReceiveTimeout = 4000;
HttpSocket.Connect(Connection);
//建立发送报头
String formatString = "{0} {1} HTTP/1.1\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: {2}\r\nHost: {3}\r\n\r\n{4}";
String SendString = string.Format(formatString, "POST", Url, Encoding.Default.GetByteCount(PostData), HostName, PostData);
byte[] SendBuffer = System.Text.Encoding.Default.GetBytes(SendString);
HttpSocket.Send(SendBuffer);
int Block = 100000;
byte[] ReceiveBuffer = new byte[Block];
Block = HttpSocket.Receive(ReceiveBuffer);
String ReceiveString = System.Text.Encoding.Default.GetString(ReceiveBuffer, 0, Block);
HttpSocket.Close();
return ReceiveString;
}
链接代码登录成功的头
HTTP/1.1 200 OK
Date: Fri, 05 Dec 2008 15:23:00 GMT
Server: Apache
Expires: 0
Cache-Control: private, post-check=0, pre-check=0, max-age=0
Pragma: no-cache
Set-Cookie: cdb_sid=O0UUQI; expires=Sat, 06-Dec-2008 15:23:00 GMT; path=/; domain=.19lou.com; httponly
Set-Cookie: cdb_cookietime=2592000; expires=Sun, 04-Jan-2009 15:23:00 GMT; path=/; domain=.19lou.com; httponly
Set-Cookie: cdb_auth=WlNXAANWD1NVBgMLBw8HVFlWAAFTVFcOAVYFUwYBUVYwaldTU1QODlMF; expires=Sun, 04-Jan-2009 15:23:00 GMT; path=/; domain=.19lou.com; httponly
Vary: Accept-Encoding,User-Agent
Content-Length: 7671
Connection: close
Content-Type: text/html失败的头
HTTP/1.1 200 OK
Date: Fri, 05 Dec 2008 15:27:15 GMT
Server: Apache
Set-Cookie: cdb_sid=n0lyUo; expires=Sat, 06-Dec-2008 15:27:15 GMT; path=/; domain=.19lou.com; httponly
Vary: Accept-Encoding,User-Agent
Content-Length: 4401
Connection: close
Content-Type: text/html如何将登录成功的信息再次加入下一次的包发送呢?
{
//解析域名
IPHostEntry IPHostInfo = Dns.GetHostEntry(HostName);
//获取域名IP地址
IPAddress IP = IPHostInfo.AddressList[0];
IPEndPoint Connection = new IPEndPoint(IP, Port);
Socket HttpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
HttpSocket.ReceiveTimeout = 4000;
HttpSocket.Connect(Connection);
//建立发送报头
String formatString = "{0} {1} HTTP/1.1\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: {2}\r\nHost: {3}\r\n\r\n{4}";
String SendString = string.Format(formatString, "POST", Url, Encoding.Default.GetByteCount(PostData), HostName, PostData);
byte[] SendBuffer = System.Text.Encoding.Default.GetBytes(SendString);
HttpSocket.Send(SendBuffer);
int Block = 100000;
byte[] ReceiveBuffer = new byte[Block];
Block = HttpSocket.Receive(ReceiveBuffer);
String ReceiveString = System.Text.Encoding.Default.GetString(ReceiveBuffer, 0, Block);
HttpSocket.Close();
return ReceiveString;
}
链接代码登录成功的头
HTTP/1.1 200 OK
Date: Fri, 05 Dec 2008 15:23:00 GMT
Server: Apache
Expires: 0
Cache-Control: private, post-check=0, pre-check=0, max-age=0
Pragma: no-cache
Set-Cookie: cdb_sid=O0UUQI; expires=Sat, 06-Dec-2008 15:23:00 GMT; path=/; domain=.19lou.com; httponly
Set-Cookie: cdb_cookietime=2592000; expires=Sun, 04-Jan-2009 15:23:00 GMT; path=/; domain=.19lou.com; httponly
Set-Cookie: cdb_auth=WlNXAANWD1NVBgMLBw8HVFlWAAFTVFcOAVYFUwYBUVYwaldTU1QODlMF; expires=Sun, 04-Jan-2009 15:23:00 GMT; path=/; domain=.19lou.com; httponly
Vary: Accept-Encoding,User-Agent
Content-Length: 7671
Connection: close
Content-Type: text/html失败的头
HTTP/1.1 200 OK
Date: Fri, 05 Dec 2008 15:27:15 GMT
Server: Apache
Set-Cookie: cdb_sid=n0lyUo; expires=Sat, 06-Dec-2008 15:27:15 GMT; path=/; domain=.19lou.com; httponly
Vary: Accept-Encoding,User-Agent
Content-Length: 4401
Connection: close
Content-Type: text/html如何将登录成功的信息再次加入下一次的包发送呢?
解决方案 »
- dataGridView
- Windows Phone 开发时 TextBox换行输入,换行显示
- C#用Socket进行TCP通信,如何接收并解析Xml数据
- DrawImage能否把图片绘制成黑白效果?
- 如何用c#调用Cygwin生成的dll?
- 如何得到进程打开的事件
- 在C#中有无办法获得对象的执行期类型?
- html利用C#进行打印如何指定打印机
- gridview问题,高手请进!
- Visual studio2012中如何自动生成代码??
- 我是个初学者,请问下“The name 'FileWatch' does not exist in the current context”是什么意思,
- 把电脑全翻过了都找不到sapi.dll
郁闷死我了...
Html = Html.Substring(0, Html.IndexOf("\r\n\r\n"));
textBox1.Text = Html.Substring(Html.IndexOf("Set-Cookie"), Html.LastIndexOf("httponly"));
我这样取
程序TMD告诉我超长了...- -~!?
问题是我要把这个COOKIE发送出去
怎么写?
已经取得了Set-Cookie: cdb_sid=8gzmVU; expires=Sat, 06-Dec-2008 15:57:20 GMT; path=/; domain=.19lou.com; httponly
Set-Cookie: cdb_cookietime=2592000; expires=Sun, 04-Jan-2009 15:57:20 GMT; path=/; domain=.19lou.com; httponly
Set-Cookie: cdb_auth=WlNXAANWD1NVBgMLBw8HVFlWAAFTVFcOAVYFUwYBUVYwaldTU1QODlMF; expires=Sun, 04-Jan-2009 15:57:20 GMT; path=/; domain=.19lou.com; httponly这个头...加载HTTP头的哪部分?