[HTTP协议练习之二]Post提交

/*POST请求*/
    NSURL* UrlPost = [NSURL URLWithString:@"http://10.2.108.11:8087/datasnap/rest/TServerMethods1/AddArticle/haidian/shahe"];
    NSMutableURLRequest* RequestPost = [[NSMutableURLRequest alloc] initWithURL:UrlPost];
    [RequestPost setHTTPMethod:@"POST"];
    [RequestPost setTimeoutInterval:5];
    NSString* PostBody = @"param abc";//这个一般字节数不超过2M
    [RequestPost setHTTPBody:[PostBody dataUsingEncoding:NSUnicodeStringEncoding]];
    [NSURLConnection sendAsynchronousRequest:RequestPost queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        if (connectionError) {
            NSLog(@"httperror:%@%ld",connectionError.localizedDescription,connectionError.code);
        }
        else
        {
            NSJSONSerialization* json = [NSJSONSerialization JSONObjectWithData:data
                                                                        options:NSJSONReadingAllowFragments
                                                                          error:nil];
            NSArray* arrResult = [json valueForKey:@"result"];
            NSLog(@"%@",arrResult[0]);
        }
    }];

有两点没有弄明白

     1,这个也是执行了函数,也和get一样,但不会写通用的格式”?后面带参数“

     2,虽然服务端能获取到参数,也就是请求的body,但是在执行函数后获得的,并没有在执行函数前获取到。

如果哪位好心人知道原因,请指点,谢谢~~

你可能感兴趣的:(http,post)