zoukankan      html  css  js  c++  java
  • http协议报头信息和主体鉴别

    http协议报头信息和主体是使用一个空行分开。这是什么空行?简单的说,那是, 。

    所以会server数据的回归 结果分离,一个是标题信息。它是一个消息的文本。

    C#例如,下面的代码:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    using System.Text.RegularExpressions;
    
    using System.IO;
    
    namespace SOCKET
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                int port = 80;
                GetSocket gs = new GetSocket();
                string result = gs.SocketSendReceive("www.baidu.com", port);
                Regex regex = new Regex("
    
    ");//以cjlovefl切割
                string[] bit = regex.Split(result);
                MessageBox.Show(bit[1]);
    
    
                StreamWriter sw = new StreamWriter("D:\1.txt");
                sw.Write(result);
                sw.Close();
            }
        }
    }
    


    当中result就是由server返回的包含头部和正文的信息。

    当中GetSocket类例如以下:

    using System;
    using System.Text;
    using System.IO;
    using System.Net;
    using System.Net.Sockets;
    using System.Windows.Forms;
    using System.Text.RegularExpressions;
    
    public class GetSocket
    {
        public Socket ConnectSocket(string server, int port)
        {
            Socket s = null;
            IPHostEntry hostEntry = null;
            // Get host related information.
            hostEntry = Dns.GetHostEntry(server);
            // Loop through the AddressList to obtain the supported AddressFamily. This is to avoid
            // an exception that occurs when the host IP Address is not compatible with the address family
            // (typical in the IPv6 case).
            foreach (IPAddress address in hostEntry.AddressList)
            {
                IPEndPoint ipe = new IPEndPoint(address, port);
                Socket tempSocket =
                    new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                tempSocket.Connect(ipe);
                if (tempSocket.Connected)
                {
                    s = tempSocket;
                    break;
                }
                else
                {
                    continue;
                }
            }
            return s;
        }
        // This method requests the home page content for the specified server.
        public  string SocketSendReceive(string server, int port)
        {
            string request = "GET / HTTP/1.0
    Host: " + server +
                "
    User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:29.0) Gecko/20100101 Firefox/29.0
    Connection: keep-alive
    
    ";
            Byte[] bytesSent = Encoding.ASCII.GetBytes(request);
            Byte[] bytesReceived = new Byte[256];
            // Create a socket connection with the specified server and port.
            Socket s = ConnectSocket(server, port);
            if (s == null)
                return ("Connection failed");
            // Send request to the server.
            s.Send(bytesSent, bytesSent.Length, 0);
            // Receive the server home page content.
            int bytes = 0;
            string page = "Default HTML page on " + server + ":
    ";
            // The following will block until te page is transmitted.
            do
            {
      
                bytes = s.Receive(bytesReceived, bytesReceived.Length, 0);
                page =page+ Encoding.ASCII.GetString(bytesReceived, 0, bytes);
            }
            while (bytes > 0);
    
    
            return page;
        }
        /*
        public static void Main(string[] args)
        {
            string host = "http://www.baidu.com";
            int port = 80;
            if (args.Length == 0)
                // If no server name is passed as argument to this program,
                // use the current host name as the default.
                host = Dns.GetHostName();
            else
                host = args[0];
            string result = SocketSendReceive("www.goodjobs.cn", port);
            StreamWriter sw = new StreamWriter("D:\1.txt");
            string w = "";
            sw.Write(result);
            sw.Close();
        }
         * */
    }
    


    测试成功!

    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    2018-2019-2 20165331《网络对抗技术》Exp 8 Web基础
    2018-2019-2 20165331《网络对抗技术》Exp7 网络欺诈防范
    2018-2019-2 20165331《网络对抗技术》Exp6 信息搜集与漏洞扫描
    2018-2019-2 20165331《网络对抗技术》Exp5 MSF基础应用
    2018-2019-2 20165331《网络对抗技术》Exp4 恶意代码分析
    2018-2019-2 20165331《网络对抗技术》Exp3 免杀原理与实践
    2018-2019-2 20165331《网络对抗技术》Exp2 后门原理与实践
    2018-2019-2 20165331《网络对抗技术》Exp1 PC平台逆向破解
    2018-2019-2《网络对抗技术》Exp0 Kali安装 Week1
    2018-2019-2 网络对抗技术 20165237 Exp9 Web安全基础实践
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/4831889.html
Copyright © 2011-2022 走看看