ISO 网络访问

NSString *address = @"http://localhost/BookReaderData/BasicGetAndPost.php";

    

    

    

    // GET

NSString *parameter = [NSString stringWithFormat:@"%@=%@", @"para", @"中文 Parameter Value"];

  // 将参数中的特殊字符串进行URL转译

parameter = [parameter stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];

   NSString *urlString = [NSString stringWithFormat:@"%@?%@", address, parameter];

   NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];

  

    NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];

    

    NSURLSessionDataTask *dataTash = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {

        

        if (error) {

            NSLog(@"%@", error);

        }

        else {

            NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

            NSLog(@"Response is %@", responseString);

        }

    }];

    [dataTash resume];

 

posted @ 2015-10-30 09:45  破水杯  阅读(155)  评论(0编辑  收藏  举报