ASIHTTPRequest is a simple encapsulation of get post requests, and asihttprequestget
1. Introduction to ASIHTTPRequest
Githubhttps: // github.com/pokeb/asi-http-request
2. ASIHTTPRequest: simple encapsulation of GET and POST requests
+ (Void) requestWithASIURL :( NSString *) urlString parmas :( NSMutableDictionary *) params httpMethod :( NSString *) method completeBlock :( RequestFinishBlock) block {// process GET request if ([[method uppercaseString] isEqualToString: @ "GET"]) {NSArray * keys = [params allKeys]; for (int I = 0; I <keys. count; I ++) {NSString * key = [keys objectAtIndex: I]; NSString * values = [params valueForKey: key]; urlString = [urlString stringByAppendingFormat: @ "& % @ = % @", key, values] ;}} NSURL * url = [NSURL URLWithString: urlString]; ASIFormDataRequest * request = [ASIFormDataRequest requestWithURL: url]; [request setRequestMethod: method]; [request setTimeOutSeconds: 10]; // process the POST request if ([[method uppercaseString] isEqualToString: @ "POST"]) {NSArray * keys = [params allKeys]; for (int I = 0; I <keys. count; I ++) {NSString * key = [keys objectAtIndex: I]; NSString * value = [params objectForKey: key]; if ([value isKindOfClass: [UIImage class]) {// NSString * filePath = [[NSBundle mainBundle] pathForResource: @ "test4" ofType: @ "gif"]; // NSData * data = [NSData dataWithContentsOfFile: filePath]; NSData * imageData = UIImageJPEGRepresentation (value, 1.0); [request addData: imageData forKey: key];} [request setPostValue: value forKey: key] ;}} [request setCompletionBlock: ^ {NSData * data = [request responseData]; NSJSONSerialization * json = [NSJSONSerialization JSONObjectWithData: data options: Unknown error: nil]; block (json) ;}]; [request startAsynchronous];}
3. Call format
NSString* urlString=@"http://192.168.1.101:8080/PengFu/jokController/getPhoneJok"; NSMutableDictionary *params=[NSMutableDictionary dictionaryWithObject:@"1 " forKey:@"rows"]; UIImage *image=[UIImage imageNamed:@"test3.gif"]; [params setObject:image forKey:@"pic"]; [params setObject:@"test gif image upload" forKey:@"status"]; [DataService requestWithASIURL:urlString1 parmas:params httpMethod:@"POST" completeBlock:^(id result) { NSLog(@"%@",result); }];
4. Note: To download the code compilation error, first import the five libraries required for the network request as follows:
If you use automatic ARC memory management, add-fno-objc-arc after source code compilation, as shown in figure
10. For the http post method, which part of the form data submitted by the user is located in HTTP? B a) starting .....................
Differences between Http Get/Post requests
1. HTTP request format:
<Request line>
<Headers>
<Blank line>
[<Request-body>]
In an HTTP request, the first line must be a request line to describe the request type, resources to be accessed, and the HTTP Version Used. Next is a header section, which describes additional information to be used by the server. After the header is a blank line, you can add any other data [called the body].
1. get is to get data from the server, and post is to send data to the server.
Get and post are just a way to pass data. get can also transmit data to the server. They are essentially sending requests and receiving results. There is only a difference between the organization format and the data size, as described in the http protocol.
2. get is to add the parameter data queue to the URL referred to by the ACTION attribute of the submission form. The values correspond to each field in the form one by one and can be seen in the URL. Post uses the HTTP post mechanism to place fields in the form and their content in the html header and send them to the URL address referred to by the ACTION attribute. You cannot see this process.
Because get is designed to transmit small data, and it is best not to modify the server data, browsers generally can see it in the address bar, but post is generally used to transmit big data, or relatively private data, so you cannot see it in the address bar. Can you see that it is not the protocol, but the browser.
3. For the get method, the server uses Request. QueryString to obtain the value of the variable. For the post method, the server uses Request. Form to obtain the submitted data.
I don't understand. How to obtain the variables is related to your server and has nothing to do with get or post. The server encapsulates these requests.
4. The data volume transmitted by get is small and cannot exceed 2 kb. The amount of data transmitted by post is large, which is generally not restricted by default. Theoretically, the maximum size of IIS4 is 80 KB, and that of IIS5 is 100KB.
There are basically no restrictions on post. I think all the files uploaded are post-based. You only need to modify the type parameter in form.
5. Low get security and high post security.
If there is no encryption, their security levels are the same. Any listener can listen to all the data. Do not believe your next software to listen to network resources,
Get is a type of request to request data from the server, while Post is a type of request to submit data to the server. In FORM, the default Method is "GET". In essence, GET and POST are only different sending mechanisms, not a single sending!
Http defines different methods for interaction with the server. There are four basic methods: GET, POST, PUT, and DELETE. The full name of a URL is a resource descriptor. We can think that a URL address is used to describe resources on a network, while GET, POST, PUT, DELETE corresponds to the query, modify, add, and DELETE operations on this resource. Here, you should have a rough understanding. GET is generally used to obtain/query resource information, while POST is generally used to update resource information.
1. According to HTTP specifications, GET is used for information retrieval, and should be secure and idempotent.
(1). The so-called security means that the operation is used to obtain information rather than modify information. In other words, GET requests generally do not have side effects. That is to say, it only obtains the resource information, just like the database query. It does not modify, add data, and does not affect the resource status.
* Note: security only indicates that the information is not modified.
(2) idempotence means that multiple requests to the same URL should return the same result. Here I will explain the concept of idempotence:
Idempotence (idempote ...... remaining full text>
What is the difference between Get and Post?
These two types of requests are commonly used in the HTTP protocol. Get requests explicitly place the form data in the URI and have restrictions on the length and data value encoding. THE Post request places the form data in the HTTP Request body without the length limit.