您的位置:首页 > 其它

Get&Post请求和MIMEType

2014-04-21 15:03 447 查看
1.GET请求:

 NSString *urlStr = [NSStringstringWithFormat:@"http://192.168.3.251/~apple/itcast/login.php?username=%@&password=%@",_userName.text,_password.text];

    

    NSURL *url = [NSURL URLWithString:urlStr];

    

    NSURLRequest *request = [NSURLRequestrequestWithURL:url];

    

    NSURLConnection *connection = [NSURLConnectionconnectionWithRequest:request
delegate:self];

    

    [connection start];

 

2.POST请求

 NSString *urlStr = [NSStringstringWithFormat:@"http://192.168.3.251/~apple/itcast/login.php"];

    NSURL *url = [NSURL URLWithString:urlStr];

    

    NSMutableURLRequest *request = [NSMutableURLRequestrequestWithURL:url];

    

    request.HTTPMethod = @"POST";

    

    NSString *bodyStr = [NSStringstringWithFormat:@"username=%@&password=%@",_userName.text,_password.text];

    request.HTTPBody = [bodyStr dataUsingEncoding:NSUTF8StringEncoding];

    

    NSURLConnection *connection = [NSURLConnectionconnectionWithRequest:request
delegate:self];

    

    [connection start];

 

3.同步请求,和异步请求

//异步请求

  [NSURLConnection sendAsynchronousRequest:<#(NSURLRequest *)#> queue:<#(NSOperationQueue *)#> completionHandler:<#^(NSURLResponse *response, NSData *data, NSError *connectionError)handler#>];

//同步请求

    [NSURLConnection sendSynchronousRequest:<#(NSURLRequest *)#> returningResponse:<#(NSURLResponse *__autoreleasing *)#> error:<#(NSError *__autoreleasing *)#>];

4.数据安全

MD5

 

5.MiMEType

.txt--------->ext/plain

.pdf-------->application/pdf

.docx ---------->application/vnd.openxmlformats-officedocument.wordprocessingml.document

.html--------->text/html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息