在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
//获取http页面函数 private string Get_Http(string a_strUrl) { string strResult ; HttpWebRequest myReq = (HttpWebRequest) WebRequestFactory.Create(a_strUrl) ; try { HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse(); Stream myStream = HttpWResp.GetResponseStream () ; StreamReader sr = new StreamReader(myStream , Encoding.Default); StringBuilder strBuilder = new StringBuilder(); while (-1 != sr.Peek()) { strBuilder.Append(sr.ReadLine()+"\r\n"); } strResult = strBuilder.ToString(); } catch(Exception exp) { strResult = "错误:" + exp.Message ; } return strResult ; } //通过同server建立tcp/ip连接,发送socket命令 private string Get_Socket_Request(string a_strServer , string a_strRequest , Int32 a_intPort) { //Set up variables and String to write to the server Encoding ASCII = Encoding.Default ; string Get = a_strRequest + "Connection: Close\r\n\r\n"; //string Get = Byte[] ByteGet = ASCII.GetBytes(Get); Byte[] RecvBytes = new Byte[256]; String strRetPage = null; // IPAddress and IPEndPoint represent the endpoint that will // receive the request IPAddress hostadd = DNS.Resolve(a_strServer.Substring(7 ,a_strServer.Length - 7)); IPEndPoint EPhost = new IPEndPoint(hostadd, a_intPort); //Create the Socket for sending data over TCP Socket s = new Socket(AddressFamily.AfINet, SocketType.SockStream, ProtocolType.ProtTCP ); // Connect to host using IPEndPoint if (s.Connect(EPhost) != 0) { strRetPage = "Unable to connect to host"; return strRetPage; } // Sent the GET text to the host s.Send(ByteGet, ByteGet.Length, 0); // Receive the page, loop until all bytes are received Int32 bytes = s.Receive(RecvBytes, RecvBytes.Length, 0); strRetPage = strRetPage + ASCII.GetString(RecvBytes, 0, bytes); while (bytes > 0) { bytes = s.Receive(RecvBytes, RecvBytes.Length, 0); strRetPage = strRetPage + ASCII.GetString(RecvBytes, 0, bytes); } return strRetPage ; } |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论