WEB开发网
开发学院网络安全安全技术 关于web应用程序安全的思考(序) 阅读

关于web应用程序安全的思考(序)

 2008-11-26 13:36:02 来源:WEB开发网   
核心提示: 以下为最一个最简单的Request请求: GET /TestWeb/test.htm HTTP/1.1Host: localhostConnection: close它表示向localhost主机请求路径为/TestWeb/test.htm的html网页,使用GET方法,关于web应用程序

以下为最一个最简单的Request请求:

GET /TestWeb/test.htm HTTP/1.1
Host: localhost
Connection: close

它表示向localhost主机请求路径为/TestWeb/test.htm的html网页,使用GET方法, 1.1版本的HTTP协议。对此请求,Windows的IIS6.0是这样给出Response的:

HTTP/1.1 200 OK
Content-Length: 12
Content-Type: text/html
Last-Modified: Wed, 05 Nov 2008 01:01:17 GMT
Accept-Ranges: bytes
Server: Microsoft-IIS/6.0
Date: Wed, 05 Nov 2008 01:01:52 GMT
Connection: close
Hello World!

包括响应状态码200,body的长度,类型,所请求文件的最后修改日期等响应头(Response Header),还有简单的Hello World! 12个字符的html响应体(Response Body)

Request请求不依赖于浏览器,事实上您可以使用任何程序语言通过网络编程来做到,以下是一个C#发送Request的例子:

using System;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text.RegularExpressions;
public class RequestDemo
{
  //建立socket连接
  private static Socket ConnectSocket(string server, int port)
  {
    Socket s = null;
    IPHostEntry hostEntry = null;
    hostEntry = Dns.GetHostEntry(server);
    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;
    }
    Console.WriteLine(s == null ? "" : "连接建立成功﹗");
    return s;
  }
  //发送request请求并接收响应字符串
  private static string SocketSendReceive(string request, string server, int port)
  {
    Byte[] bytesSent = Encoding.ASCII.GetBytes(request);
    Byte[] bytesReceived = new Byte[256];
    Socket s = ConnectSocket(server, port);
    if (s == null)
      return ("连接失败﹗");
    Console.WriteLine("正在发送请求...");
    s.Send(bytesSent, bytesSent.Length, 0);
    int bytes = 0;
    StringBuilder responsestr = new StringBuilder();
    Console.WriteLine("正在接收web服务器的回应...");
    do
    {
      bytes = s.Receive(bytesReceived, bytesReceived.Length, 0);
      responsestr.Append(Encoding.UTF8.GetString(bytesReceived, 0, bytes));
    }
    while (bytes > 0);
    return responsestr.ToString();
  }
  public static void
Main
(string[] args)
  {
    //读取在Request.txt中的Request字符串(request.txt末尾至少要留个空行,表明Request结束)
  string requeststr = File.ReadAllText("C:  mp
equest.txt")
  Console.WriteLine("请求字符串如下﹕n{0}n", requeststr;
    //发送且接收Response
    string result = SocketSendReceive(requeststr, "localhost", 80);
    Console.WriteLine("n{0}", result);
    Console.ReadLine();
  }
}

上一页  1 2 3 4 5 6 7  下一页

Tags:关于 web 应用程序

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接