[英]Difference between Get and post method in comparision with HTTP and REST
[英]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.