基于Express框架使用POST上传文件

这篇博客介绍了HTTP协议的基础知识,重点讲解了POST方法在HTTP请求中的作用,特别是如何在Express框架下处理文件上传。文章详细阐述了HTTP请求的组成部分,包括请求行、请求方法等,并提及POST用于创建新资源。同时,提到了Web表单提交数据的两种方式(GET和POST),以及在POST请求中处理文件上传的实现方法,提供了使用Node.js和Express的代码示例。
摘要由CSDN通过智能技术生成

What 

"The Hypertext Transfer Protocol (HTTP) is an application-level  protocol for distributed, collaborative, hypermedia information  systems."[10]


  "HTTP is a stateless request/response protocol that operates by exchanging messages across a reliable transport- or session-layer 'connection' "[10]


"A HTTP client is a program that extabilishes a connection to a server for purpose of sending one or more HTTP requests."[10]


"A HTTP server is a program that accepts connections in order to service HTTP requests by sending HTTP responses." [10]


"The terms 'client' and 'server' refer only to roles that these programs perform for a particular connection" [10]


How


"Most HTTP Communication consists of a retrieval request  (GET) for a representation of some resource identified by a URI."

"HTTP relies upon the Uniform Resource Identifier (URI) standard to indicate the target resource and relationships between resources." [10]

"Messages are passed in a format similar to that used by Internet mail and the Multipurpose Internet Mail Extensions (MIME)"

"The Hypertext Transfer Protocol (HTTP) is an application-level  protocol for distributed, collaborative, hypermedia information  systems."[10]
 
"The HTTP protocol is a request/response protocol. A client sends a request to the server in the form of a request method, URI, and  protocol version, followed by a MIME-like message containing request  modifiers, client information, and possible body content over a  connection with a server. The server responds with a status line,  including the message's protocol version and a success or error code, followed by a MIME-like message containing server information, entity  metainformation, and possible entity-body content."[10]

"A client sends an HTTP request to a server in the form of a request message, beginning with a request-line that includes a method, URI, and protocol version, followed b header fields containning request modifiers, client information, and reqpresentation metata, an empty line to indicate the end of the header section, and finally a message body containing the payload body." [10]


"A server responds to a client’s request by sending one or more HTTP response messages, each beginning with a status line that includes the protocol version, a success or error code, and textual reason phrase , possibly followed by header fields containing server information, resource metadata, and representation metadata, an empty line to indicate the end of the header section, and finally a message body containing the payload body. " [10]

An Example[10]:

Client request:

 
GET /hello.txt HTTP/1.1
 User-Agent: curl/7.16.3 libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3
 Host: www.example.com
 Accept-Language: en, mi

Server response:

 
HTTP/1.1 200 OK
 Date: Mon, 27 Jul 2009 12:28:53 GMT
 Server: Apache
 Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT
 ETag: "34aa387-d-1568eb00"
 Accept-Ranges: bytes
 Content-Length: 51
 Vary: Accept-Encoding
 Content-Type: text/plain
 Hello World! My payload includes a trailing CRLF.

Request
   "A request message from a client to a server includes, within the  first line of that message, the method to be applied to the resource,  the identifier of the resource, and the protocol version in use."[10]

        Request       = Request-Line              ; Section 5.1
                        *(( general-header        ; Section 4.5
                         | request-header         ; Section 5.3
                         | entity-header ) CRLF)  ; Section 7.1
                        CRLF
                        [ message-body ]          ; Section 4.3


Request-Line(请求行)[10]
   "The Request-Line be

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值