当前位置: 首页 > 编程日记 > 正文

http编程学习(C#)

《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

相关文章:

服务器远程免密登录

1. 生成本地密钥 ssh-keygen2. 将密钥上传到服务器 ssh-copy-id -p port username192.128.128.128 3. 创建登录脚本 ssh -p port username192.128.128.128 转载于:https://www.cnblogs.com/yeran/p/11348045.html

如何触发AspxGridview的PageIndexChanged 客户端事件

?最近在使用AspxGridview控件时,遇到一个问题,就是在触发AspxGridview分页事件之后,需要在执行js事件,找了好久,在官网上找到处理的办法。 就是在cs页面设置变量在触发PageIndexChanged事件后,改…

Mysql 多表使用 Case when then 遇到的坑

前言: 在做一个订单导出时,遇到多表都含有state这个字段,含有多个状态首先想到的是: case colume when condition then result when condition then result when condition then result else result end 当正常试着写代码时会发现…

nginx反向代理原理及配置详解

nginx概述nginx是一款自由的、开源的、高性能的HTTP服务器和反向代理服务器;同时也是一个IMAP、POP3、SMTP代理服务器;nginx可以作为一个HTTP服务器进行网站的发布处理,另外nginx可以作为反向代理进行负载均衡的实现。 这里主要通过三个方面简…

小鱼易连电脑版_生活多么美好 篇十六:我的桌面改造,有绿植,有小鱼,有大音箱...

原标题:生活多么美好 篇十六:我的桌面改造,有绿植,有小鱼,有大音箱生活多么美好 篇十六:我的桌面改造,有绿植,有小鱼,有大音箱 2020-11-06 22:13:312点赞1收藏1评论想攒一…

菜鸟初涉SQL Server的总结

看完了一遍耿建玲老师的视频,讲的很多,一些细节的东西还是很难去把控。准备总结自己觉得无从下手,觉得很难去把控这个宏观和细节的平衡。但如果不去做这个工作的话,我可能永远都不能学会怎样去做好总结。总之,先这样去…

extjs4.0视频教程下载

发现www.uspcat.com 学习extjs4.0不错的论坛啊 http://www.uspcat.com/portal.php 视频教程下载 http://www.uspcat.com/forum.php?modviewthread&tid197&extra 转载于:https://blog.51cto.com/3450037/687004

开源依旧:再次分享一个进销存系统

开篇 我之前发过一篇博文《两天完成一个小型工程报价系统(三层架构)》,不少朋友向我要源码学习,后来久而久之忘记回复了。今天我再分享一个进销存系统,只为学习,没有复杂的框架和设计模式,有的是我个人的理解&#xff…

kotlin + springboot启用elasticsearch搜索

参考自: http://how2j.cn/k/search-engine/search-engine-springboot/1791.html?p78908 工具版本: elasticsearch 6.2.2、 kibana 6.2.2, 下载地址: elasticsearch、kibana 下载demo 1、kotlin版springboot项目创建 访问https:/…

insert 语句的选择列表包含的项多于插入列表中的项_如何定义和使用Python列表(Lists)

Python中最简单的数据集合是一个列表(list)。列表是方括号内用逗号分隔的任何数据项列表。通常,就像使用变量一样,使用符号为Python列表分配名称。 如果列表中包含数字,则不要在其周围使用引号。 例如,这是测试成绩的列表&#xf…

数据结构之主席树

这里讲静态的主席树,关于静态区间第k小。(有兴趣的朋友还可以去看看我写的整体二分,代码实现略优于主席树我觉得,当然静态主席树是很好写的) 题目描述: 题目描述 如题,给定N个正整数构成的序列&…

k-d tree算法的研究

By RaySaint 2011/10/12 动机 先前写了一篇文章《SIFT算法研究》讲了讲SIFT特征具体是如何检测和描述的,其中也提到了SIFT常见的一个用途就是物体识别,物体识别的过程如下图所示: 如上图(a),我们先对待识别的物体的图像进行SIFT特…

Unicode,UTF-32,UTF-16,UTF-8到底是啥关系?

编码的目的,就是给抽象的字符赋予一个数值,好在计算机里面表示。常见的ASCII使用8bit给字符编码,但是实际只使用了7bit,最高位没有使用,因此,只能表示128个字符;ISO-8859-1(也叫Latin-1&#xf…

HDU 4407 sum 容斥原理

算法: 利用数据1...N的性质&#xff0c;求与P的互质的个数&#xff0c;位运算&#xff0c;容斥定理。。 #include<stdio.h> #include<stdlib.h> #include<string.h> #include<iostream> #include<vector> #include<string> #include<ma…

uniapp中qrcode生成二维码后传的参数不见了_阿虚教你制作动态二维码,超详细教程!

这篇教程很早之前就答应几个粉丝要写&#xff0c;拖的有点久了。内容比较多&#xff0c;先上个目录阿虚的教程会迟到&#xff0c;但永远不会缺席。hahahahhaha...一、 先说一下今天要教的内容ʕ•̫͡•ོʔ•̫͡•ཻʕ•̫͡•ʔ•͓͡•ʔ 1.不准备教的类似这种二维码&#…

得到最后的自增长列的最后一个值

declare Table_name varchar(60) set Table_name aa; Select so.name Table_name, --表名字 sc.name Iden_Column_name, --自增字段名字 ident_current(so.name) curr_value, --自增字段当前值 ident_incr(so.name) incr_value, --自增字段增长值 ident_seed(so.name) s…

关于C语言中 字符串常量的问题

昨天晚上我编写了一段简短的C语言程序&#xff08;Linux环境下&#xff09;&#xff0c;编译能够通过&#xff0c;但是运行的时候老是报段错误。我当时非常郁闷&#xff0c;因为代码不长。其中主函数中有这样一句话&#xff1a; char *str"epmzm bpmzm qa eqtt bpmzm qa i…

WPF布局(2) 使用的DockPanel面板进行简单的布局

DockPanel 面板是根据外边缘进行控件的拉伸&#xff0c;DockPanel的LastChildFill属性设置为True 时&#xff0c;最后一个添加的控件将占满剩余空间。 <DockPanel LastChildFill"True"><Button DockPanel.Dock"Top">Top Button</Button>…

合并两个有序数组(重新开始)

在看分治算法的时候&#xff0c;想先自己写写合并的代码&#xff0c;还是不熟练啊&#xff01; 为了保持对代码的敏感度&#xff0c;要保持练习。加油&#xff01; public class JustDoIt0803 {/*** 分治算法学习前准备*/public static void main(String[] args) {int[] x new…

miui通知栏要点两下_MIUI免费主题分享,半透明通知栏很好看,另附壁纸!

最近很少分享主题&#xff0c;主要原因是没发现太好的&#xff0c;甚至主题连一处漂亮的点都没有&#xff0c;不过还是有一款状态栏很精致的主题&#xff0c;这里分享大家&#xff0c;可用作混搭使用&#xff01;主题名&#xff1a;Blur首先主题是免费的&#xff0c;也之所以免…

C#中的委托和事件(续)

引言 如果你看过了 C#中的委托和事件 一文&#xff0c;我想你对委托和事件已经有了一个基本的认识。但那些远不是委托和事件的全部内容&#xff0c;还有很多的地方没有涉及。本文将讨论委托和事件一些更为细节的问题&#xff0c;包括一些大家常问到的问题&#xff0c;以及事件访…

优先级队列实现哈夫曼树的编码和译码

//优先级队列实现的哈夫曼树的编码和译码 #include<iostream> #include<queue> #include<string> using namespace std; class Node { public: float weight; Node* left; Node* right; char ch; Node(float…

Git,Github和Gitlab简介和使用方法

什么是Git Git是一个版本控制系统&#xff08;Version Control System&#xff0c;VCS&#xff09;。 版本控制是一种记录一个或若干文件内容变化&#xff0c;以便将来查阅特定版本修订情况的系统。 多年前&#xff0c;我在法国做第一个实习时&#xff08;2011年&#xff09;&a…

Win10控制桌面图标显示

1、桌面鼠标右键&#xff0c;进入个性化 2、进入主题&#xff1a; 3、 转载于:https://www.cnblogs.com/132818Creator/p/11356237.html

如何查看笔记本电脑配置参数_教你如何查看 MacBook 配置,超简单

相信很多人都会遇到这样的情况&#xff1a;当有人问起你的 MacBook 配置时&#xff0c;你却愣了&#xff0c;因为你自己都没注意或者查看过。实际上&#xff0c;有很多人对自己的电脑配置都不是很清楚&#xff0c;本期Mac毒就来教教你如何快速查看苹果电脑的相关配置。1、首先&…

为什么以太网帧的长度最短64字节,最长1518字节?

1.碰撞槽时间 假设公共总线媒体长度为S&#xff0c;帧在媒体上的传播速度为0.7C&#xff08;光速&#xff09;&#xff0c;网络的传输率为R&#xff08;bps&#xff09;&#xff0c;帧长为L&#xff08;bps&#xff09;&#xff0c;tPHY为某站的物理层时延&#xff1b; 则有&a…

PHP 利用AJAX获取网页并输出(原创自Zjmainstay)

看点&#xff1a; 1、file_get_contents超时控制。 2、页面编码判断。 3、键盘Enter键捕捉响应。 4、键盘event兼容处理。//event event || window.event; 5、XMLHttpRequest 和 jQuery 两种实现方案。 6、页面及源码同时展示。 XMLHttpRequest版本 get_web.php <?phphead…

TCP/IP 协议栈4层结构及3次握手4次挥手

TCP/IP 协议栈是一系列网络协议的总和&#xff0c;是构成网络通信的核心骨架&#xff0c;它定义了电子设备如何连入因特网&#xff0c;以及数据如何在它们之间进行传输。TCP/IP 协议采用4层结构&#xff0c;分别是应用层、传输层、网络层和链路层&#xff0c;每一层都呼叫它的下…

简述BT下载技术及其公司发展现状

一、 BT下载技术是什么&#xff1f;谁发明的&#xff1f; 2003年&#xff0c; 软件工程师Bram Cohen发明了BitTorrent协议&#xff08;俗称“BT下载”&#xff09;&#xff0c;其采用高效的软件分发系统和P2P技术共享大体积文件&#xff08;如一部电影或电视节目&#xf…

php要怎么使用imagettftext_延长防腐木使用要怎么做呢?

木结构基层的处理&#xff1a;设计施工中应充分保持防腐木材与地面之间的空气流通&#xff0c;可以更有效延长木结构基层的寿命。制作安装防腐木时&#xff0c;防腐木之间需留0.2-1CM的缝隙(根据木材的含水率再决定缝隙大小&#xff0c;木材含水率超过30&#xff05;时不应超过…