[HTTP协议练习之一]Get请求

    /*GET请求*/
    NSURL *url = [[NSURL alloc] initWithString:@"http://10.2.108.11:8088/datasnap/rest/TServerMethods1/AddArticle/beijing/haidian"];
    NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"get"];
    [request setTimeoutInterval:5];
    NSOperationQueue* queue = [[NSOperationQueue alloc] init];
    [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if (connectionError) {
            NSLog(@"httperror:%@%ld",connectionError.localizedDescription,connectionError.code);
        }
        else
        {
            NSInteger ResponsCode = [(NSHTTPURLResponse*) response statusCode];
            NSString * ResponsString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
            NSLog(@"HttpResponsCode:%ld", ResponsCode);
            NSLog(@"HttpResponsString:%@", ResponsString);
        }
    }];

总结:1,请求的url里面不支持中文字。

           2,返回的是个json格式的数据,如果变量可变,那么也返回。httpResponsString:{"result":["beijingHello","haidianWOrld",false]}

     3,服务器采用了restful框架。

你可能感兴趣的:(http协议,url,get)