《HTTP Programming Recipes for C# Bots》

第一章

选择GET还是POST取决于传送到服务器的数据的多少。GET传送的数据少,POST几乎对传送的数据无限制。

It is important to note that only one physical file is transferred per HTTP request.

每次HTTP请求只传送了一个物理文件

调用顺序:

• Step 1: Obtain a HttpWebRequest object.

获取一个HttpWebRequest对象

• Step 2: Set any HTTP request headers.

设置HTTP请求头

• Step 3: POST data, if this is a POST request.

附上数据,如果是POST请求?

• Step 4: Obtain a HttpWebResponse object.

获取一个HttpWebResponse对象

• Step 4: Read HTTP response headers.

读取HTTP响应头

• Step 5: Read HTTP response data.

读取HTTP响应数据

Typical Request Headers
GET /1/1/typical.php HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, */*
Referer: http://www.httprecipes.com/1/1/
Accept-Language: en-us
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;
.NET CLR 1.1.4322; .NET CLR 2.0.50727)
Host: www.httprecipes.com
Connection: Keep-Alive

There are really two parts to the headers: the first line and then the rest of the header
lines. The first line, which begins with the request type, is the most important line in the
header block, and it has a slightly different format than the other header lines. The request
type can be GET, POST, HEAD, or one of the other less frequently used headers. Browsers
will always use GET or POST. Following the request type is the file that is being requested.
In the above request, the following URL is being requested:
http://www.httprecipes.com/1/1/typical.phpThere are really two parts to the headers: the first line and then the rest of the header
lines. The first line, which begins with the request type, is the most important line in the
header block, and it has a slightly different format than the other header lines. The request
type can be GET, POST, HEAD, or one of the other less frequently used headers. Browsers
will always use GET or POST. Following the request type is the file that is being requested.
In the above request, the following URL is being requested:
http://www.httprecipes.com/1/1/typical.phpThere are really two parts to the headers: the first line and then the rest of the header
lines. The first line, which begins with the request type, is the most important line in the
header block, and it has a slightly different format than the other header lines. The request
type can be GET, POST, HEAD, or one of the other less frequently used headers. Browsers
will always use GET or POST. Following the request type is the file that is being requested.
In the above request, the following URL is being requested:
http://www.httprecipes.com/1/1/typical.php

The above URL is not represented exactly as seen above in the request header. The
“Host” header line in the header names the web server that contains the file. The request
shows the remainder of the URL, which in this case is /1/1/typical.php. Finally, the
third thing that the first line provides is the version of the HTTP protocol being used. As of
the writing of this book there are only two versions currently in widespread use:
• HTTP/1.1
• HTTP/1.0
This book only deals with HTTP 1.1. Because this book is about writing programs to connect
to web servers, it will be assumed that HTTP 1.1 is being used, which is what C# uses
when the C# HTTP classes are used.
The lines after the first line make up the actual HTTP headers. Their format is colon
delimited. The header name is to the left of the colon and the header value is to the right. It
is valid to have two of the same header names in the same request. Two headers of the same
name are used when cookies are specified. Cookies will be covered in Chapter 8, “Handling
Sessions and Cookies.”
The headers give a variety of information. Examining the headers shows type of browser
being used as well as the operating system, as well as other information. In the headers listed
above in Listing 1.3, the Internet Explorer 7 browser was being used on the Windows XP
platform.
The headers finally terminate with a blank line. If the request had been a POST, any
posted data would follow the blank line. Even when there is no posted data, as is the case
with a GET, the blank line is still required.
A web server should respond to every HTTP request from a web browser. The web
server’s response is discussed in the next section.

HTTP Response Headers
When the web server responds to a HTTP request, HTTP response header lines are
sent. The HTTP response headers look very similar to the HTTP request headers. Listing
1.4 shows the contents of typical HTTP response headers.

Listing 1.4: Typical Response Headers
HTTP/1.1 200 OK
Date: Sun, 02 Jul 2006 22:28:58 GMT
Server: Apache/2.0.40 (Red Hat Linux)
Last-Modified: Sat, 29 Jan 2005 04:13:19 GMT
ETag: "824319-509-c6d5c0"
Accept-Ranges: bytes
Content-Length: 1289
Connection: close
Content-Type: text/html

As can be seen from the above listing, at first glance, response headers look nearly the
same as request headers. However, look at the first line.
Although the first line is space delimited as in the request, the information is different.
The first line of HTTP response headers contains the HTTP version and status information
about the response. The HTTP version is reported as 1.1, and the status Code, 200, means
“OK,” no error. Also, this is where the famous error code 404 (page not found) comes
from.
Error codes can be grouped according to the digit in their hundreds position:
• 1xx: Informational - Request received, continuing process
• 2xx: Success - The action was successfully received, understood, and accepted
• 3xx: Redirection - Further action must be taken in order to complete the request
• 4xx: Client Error - The request contains bad syntax or cannot be fulfilled
• 5xx: Server Error - The server failed to fulfill an apparently valid request
Immediately following the headers will be a blank line, just as was the case with HTTP
requests. Following the blank line delimiter will be the data that was requested. It will be
of the length specified in the Content-Length header. The Content-Length
header in Listing 1.4 indicates a length of 1289 bytes. For a list of HTTP codes, refer to Appendix
E, “HTTP Response Codes.”

转载于:https://www.cnblogs.com/gitran/archive/2012/07/30/3644156.html

http编程学习(C#)相关推荐

  1. Unity 3D游戏代码编程学习教程 Full Guide To Unity 3D C#: Learn To Code Making 3D Games

    Unity 3D游戏代码编程学习教程 Full Guide To Unity 3D & C#: Learn To Code Making 3D Games Full Guide To Unit ...

  2. python windows编程_在Windows下配置Python编程学习环境

    一.需求: 之前是在Linux环境下进行Python的学习,每次开虚拟机觉得有点麻烦,希望可以直接在Windows的dos命令行下进行Python编程学习. 二.安装软件 直接从官网下载这两个软件安装 ...

  3. 多线程编程学习笔记——async和await(三)

    接上文 多线程编程学习笔记--async和await(一) 接上文 多线程编程学习笔记--async和await(二) 五.   处理异步操作中的异常 本示例学习如何在异步函数中处理异常,学习如何对多 ...

  4. 20万Star的编程学习教程:让你的编码之路事半功倍!

    中国有句古话,英雄不问出处,有很多优秀的程序猿都是半路入行,最后成为行业标杆,所以无论小伙伴现在在做什么是什么基础起步,只要肯好好学习,肯定有机会成就一番伟业(最好的办法就是关注小编天天一起学习进步~ ...

  5. 编程学习初体验(4. 编程的核心)

    初学编程的朋友,总觉得写程序是件单纯的事情:知道如何使用一种语言,熟悉一个开发环境,了解系统的编程接口(API)就已经能够成为一个合格的程序员 了.在我刚刚接触编程学习的时候,我也是这么认为的.这种认 ...

  6. 0122 - EOS 编程学习日志(1)

    EOS 编程到底是什么呢.学什么呢? 抱歉,我现在也不无法回答.不过,我可以告诉你我做了哪些尝试.目前的理解,以及下一步还要做什么. 首先,EOS 开发最重要的文档自然是在 GitHub: githu ...

  7. 窗口消息——Windows核心编程学习手札之二十六

    窗口消息 --Windows核心编程学习手札之二十六 Windows允许一个进程至多建立10000个不同类型的用户对象(user object):图符.光标.窗口类.菜单.加速键表等,当一个线程调用一 ...

  8. 未处理异常和C++异常——Windows核心编程学习手札之二十五

    未处理异常和C++异常 --Windows核心编程学习手札之二十五 当一个异常过滤器返回EXCEPTION_CONTINUE_SEARCH标识符时是告诉系统继续上溯调用树,寻找另外的异常过滤器,但当每 ...

  9. 异常处理程序和软件异常——Windows核心编程学习手札之二十四

    异常处理程序和软件异常 --Windows核心编程学习手札之二十四 CPU负责捕捉无效内存访问和用0除一个数值这种错误,并相应引发一个异常作为对错误的反应,CPU引发的异常称为硬件异常(hardwar ...

  10. 结束处理程序——Windows核心编程学习手札之二十三

    结束处理程序 --Windows核心编程学习手札之二十三 使用SEH可以只关注程序要完成任务,而运行中发生的错误,系统将会发现并通知.Windows引入SHE是为了便于操作系统的开发,使用SHE所造成 ...

最新文章

  1. 利用Python基础代码语句,实现2G时代文字小游戏,世界如此简单
  2. 【错误记录】Android Studio 4.2.1 编译报错 ( Kotlin 版本推荐设置 1.5.0 )
  3. 用四种方法Python求出两个有序数组中的中位数
  4. GDCM:gdcm::Module的测试程序
  5. MessageDlg
  6. Java的三种工厂模式
  7. (八):构建WineLib DLL
  8. java protobuffer 网络_C#与Java通过protobuf进行网络通信过程中遇到的问题
  9. 人脸对齐(十五)--PIFA with a Single CNN
  10. 关于最近打断点的总结
  11. iOS打包后收不到推送信息
  12. Jmeter基础教程
  13. 大一计算机理论知识测试题,2017计算机基础大一考试试题「附答案」
  14. day09渗透简单测试流程以及PKI实验
  15. 为什么有了哈希算法还需要一致性哈希?
  16. 从营收提升到品牌资产增长,私域时代的购物节跃迁
  17. ANSYS预紧力螺栓连接结构(一HyperMesh添加接触单元)
  18. 实验吧CTF练习题---WEB---猫抓老鼠解析
  19. bpduguard使用在接着虚拟机的服务器上,避免网络环路:STP和VMware vSwitch
  20. Mac外接显示器调色方法

热门文章

  1. 2022-2028年中国环保设备行业投资分析及前景预测报告
  2. 2022-2028年中国高强度钢行业投资分析及前景预测报告
  3. dataframe,python,numpy 问题索引1
  4. PyTorch 高级实战教程:基于 BI-LSTM CRF 实现命名实体识别和中文分词
  5. 八种基本类型的包装类你真的懂了?
  6. Intel发布FPGA
  7. Python API vs C++ API of TensorRT
  8. Cookie和Session的区别与联系
  9. ContentProvider是如何实现数据共享的
  10. 2021年大数据Hadoop(十五):Hadoop的联邦机制 Federation