简体   繁体   中英

what is the difference between GET and POST method in rest API IOS?

i have use this code but i don't know why we use POST and why we use GET in rest API?

-(IBAction)ClickSignUP:(id)sender
     {
        NSString *urlLoc = @"YOUR URL";


        NSLog(@"%@",urlLoc);

        NSString * requestString = [NSString stringWithFormat:@"Name=%@&Email=%@&Password=%@&MobileNumber=%@&BloodGroup=%@&DeviceID=%@&City=%@&DeviceType=I",txtName.text,txtEmail.text,txtPassword.text,txtMobileno.text,strBlood,strDeviceID,txtCity.text];

            NSData *postData = [requestString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
            NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];
            request = [[NSMutableURLRequest alloc] init];
            [request setURL:[NSURL URLWithString:urlLoc]];
            [request setHTTPMethod:@"POST"];
            [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
            [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
            [request setHTTPBody:postData];
            PostConnectionSignUp = [[NSURLConnection alloc] initWithRequest:request delegate:self];

        }

how we can integrate kingfisher image loading in swift 3.0

pod 'Kingfisher', '~> 4.6.1.0'
  import Kingfisher    
imgVUser.kf.setImage(with: URL(string: data.propertyImage), placeholder: UIImage.init(named: "placeholder"), options: [.transition(.fade(1))], progressBlock: nil, completionHandler: nil)

how we can integrate KRProgress Indicator in swift 3.0

pod 'KRProgressHUD', '~> 3.1.1.0'

DispatchQueue.main.async {          
                KRProgressHUD.show()    
            }

DispatchQueue.main.async {
                KRProgressHUD.dismiss()
            }

Main difference between GET and POST

GET - When you get some data from URL Like name, address, gender etc. GET methods is only use for retrive data from URL.

Post - When you send some data on server then use post methods.

GET : The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI. If the Request-URI refers to a data-producing process, it is the produced data which shall be returned as the entity in the response and not the source text of the process, unless that text happens to be the output of the process.

The semantics of the GET method change to a "conditional GET" if the request message includes an If-Modified-Since, If-Unmodified-Since, If-Match, If-None-Match, or If-Range header field. A conditional GET method requests that the entity be transferred only under the circumstances described by the conditional header field(s). The conditional GET method is intended to reduce unnecessary network usage by allowing cached entities to be refreshed without requiring multiple requests or transferring data already held by the client.

POST : The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line. POST is designed to allow a uniform method to cover the following functions:

  - Annotation of existing resources;
  - Posting a message to a bulletin board, newsgroup, mailing list,
    or similar group of articles;
  - Providing a block of data, such as the result of submitting a
    form, to a data-handling process;
  - Extending a database through an append operation.

The actual function performed by the POST method is determined by the server and is usually dependent on the Request-URI. The posted entity is subordinate to that URI in the same way that a file is subordinate to a directory containing it, a news article is subordinate to a newsgroup to which it is posted, or a record is subordinate to a database.

Read this LINK for more information

your code is using post method.

ie

Post Method:
urlLoc = this is url before. //i.e www.google.com
requestString = you are add your textfield value after urlLoc. //name='Bhadresh'
- this method user doesn't see requestString data in browser url

Get Method:
urlLoc + requstString = website.com/directory/index.php?name=YourName&bday=YourBday
- this method user see requestString data in browser url

More infomation:: What is the difference between POST and GET?

GET和POST方法都用于通过HTTP协议将数据从客户端传输到服务器,但是POST和GET方法之间的主要区别在于GET携带附加在URL字符串中的请求参数,而POST携带在消息正文中的请求参数,这使其更安全使用HTTP协议将数据从客户端传输到服务器。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM