Multithreaded learning the next day

Source: Internet
Author: User
Tags http post

Actually, I don't know what to do with the title today.

One: POST

1. If you want to pass large amounts of data, such as file uploads, you can only use POST requests

2.get is less secure than post, and if it contains sensitive information, it is recommended to use post

Classification of 3.post requests

is divided into two categories, which differ in the format of the requested object.

A class and get similar, use the URL to host the request information, more for login registration, fill in the form and other operations (this way of POST request can also be implemented with GET request, but get request, the data sent is bare)

Another class uses NSData (binary data) to host request information, which is used for uploading files

Two: Nsmutableurlrequest

Nsmutableurlrequest is a subclass based on nsurlrequest, and the common methods are:

1. Set the request timeout wait time (more than this time, the request fails even if it expires)

-(void) Settimeoutinterval: (nstimeinterval) seconds;

2. Setting the Request method

-(void) Sethttpmethod: (NSString *) method;

3. Set the request body:

-(void) Sethttpbody: (NSData *) data;

4. Set the request header

-(void) SetValue: (NSString *) value forhttpheaderfiled: (NSString *) field;

The use of three webserver

Start: sudo apachectl start

Stop: sudo apachectl stop

Restart: sudo apachectl restart

View Apache version Httpd-v

Cgi-executables: Storing CGI programs

Documents: Storing Web pages

Share: Storage network resources

The format of the HTTP POST request for the four uploaded images:

Java code

1. Content-type:multipart/form-data, boundary=aab03x

2.

3. --aab03x

4. content-disposition:form-data; name= "Field1"

5.

6. Hello boris!

7. --aab03x

8. content-disposition:form-data; name= "pic"; filename= "Boris.png"

9. Content-type:image/png

10.

One by one ... . contents of Boris.png ...

--aab03x-- .

The first line specifies that the HTTP POST request is encoded as multipart/form-data (this must be used for uploading the file).

Boundary=aab03x explained that aab03x was the dividing line. Like--aab03x is the meaning of a dividing line.

Content-disposition:form-data; Name= "Field1"

Hello boris!

This statement declares the name of a field in the request, such as field1 and the value of the field, such as Hello boris!

This is similar to the <input name= "field1" type= "text" value= "Hello boris!" in form form />

A blank line in the middle is required.

Separate fields are separated by dividing lines, which require a separate line, such as--aab03x--

The next line of demarcation is the next field

Content-disposition:form-data; Name= "pic"; Filename= "Boris.png"

Content-type:image/png

... contents of boris.png ...

--aab03x--

Here we declare the variable pic, which is the file we want to pass, and we need to specify file Name:filename= "Boris.png" when uploading files.

And you need to specify the format of the file on the following line: Content-type:image/png

... contents of boris.png ... Here is boris.png binary content, such as <89504e47 0d0a1a0a 0000000d 49484452 000000b4 000000b4 08020000 00b2af91 65000020 00494441 547801 2c dd79b724 6b7616f6 8c888c88 8c9c8733 55ddb1d5 6a0db486 06218401 ...

At the end of the HTTP POST request, there needs to be a dividing line, but there are both before and after:--aab03x--

The above formats are HTTP specifications, each blank line, and spaces are required.

The code will be shown in the next blog post.

Multithreaded learning the next day

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.