繁体   English   中英

rest API IOS中的GET和POST方法有什么区别?

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

我已经使用了这段代码,但是我不知道为什么我们要使用POST以及为什么要在rest API中使用GET

-(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];

        }

我们如何在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)

如何在Swift 3.0中集成KRProgress Indicator

pod 'KRProgressHUD', '~> 3.1.1.0'

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

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

GET和POST之间的主要区别

GET-当您从URL获取一些数据时,例如姓名,地址,性别等。GET方法仅用于从URL检索数据。

发布-当您在服务器上发送一些数据时,请使用发布方法。

GET :GET方法意味着检索由Request-URI标识的任何信息(以实体形式)。 如果Request-URI指的是数据产生过程,则应将产生的数据作为响应中的实体而不是过程的源文本作为实体返回,除非该文本恰好是过程的输出。

如果请求消息包含If-Modified-Since,If-Unmodified-Since,If-Match,If-None-Match或If-Range标头字段,则GET方法的语义将更改为“条件GET”。 条件GET方法仅在条件标头字段描述的情况下才请求转移实体。 有条件的GET方法旨在通过允许刷新缓存的实体而无需多个请求或传输客户端已经拥有的数据来减少不必要的网络使用。

POST :POST方法用于请求源服务器接受请求中包含的实体作为请求行中Request-URI标识的资源的新从属。 POST旨在允许采用统一的方法来覆盖以下功能:

  - 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.

POST方法执行的实际功能由服务器确定,通常取决于Request-URI。 张贴的实体是从属于该URI以同样的方式,一个文件从属于包含它的目录,新闻文章从属于一个新闻组,它张贴,或记录从属于一个数据库。

阅读此链接以获取更多信息

您的代码正在使用post方法。

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

详细信息:: POST和GET有什么区别?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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