【发布时间】:2015-08-21 05:16:38
【问题描述】:
我想用套接字发送 GET/POST 请求,我有这个代码:
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(Url, 80);
byte[] contentLenght = Encoding.ASCII.GetBytes(Data);
string[] masRequestString ={
"GET /"+Data+" HTTP/1.1\r\n" ,
"Host: "+Url+"\r\n",
"User-Agent: "+textBox1.Text+"\r\n",
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n",
"Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n",
"Referer: "+textBox2.Text+"\r\n"};
string request = string.Concat(masRequestString);
Byte[] bytesSent = Encoding.ASCII.GetBytes(request);
socket.Send(bytesSent, bytesSent.Length, 0);
Byte[] bytesReceived = new Byte[0x400];
int bytes = socket.Receive(bytesReceived, bytesReceived.Length, 0);
string content = Encoding.ASCII.GetString(bytesReceived, 0, bytes);
当我尝试发送请求时,嗅探器看不到它。为什么?
【问题讨论】:
标签: c# sockets get request send