iOS.访问 Web Service.MKNetworkKit_GET

#import <UIKit/UIKit.h>
#import "T20140628025200NSNumber+Message.h"
#import "T20140628025200NSString+URLEncoding.h"
#import "MKNetworkEngine.h"
#import "MKNetworkOperation.h"

@interface T20140628025200ViewController : UITableViewController

@property (nonatomic,strong) NSMutableArray *listData;

//接收从服务器返回数据。
@property (strong,nonatomic) NSMutableData *datas;

// 查询所有
-(void)findAll;

@end
#import "T20140628025200ViewController.h"

@interface T20140628025200ViewController ()

@end

@implementation T20140628025200ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    // 1、初始化数据
    [self findAll];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

#pragma mark table dataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.listData.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 1、初始化重用Cell
    static NSString *reUseCell = @"reUseCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reUseCell];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reUseCell];
    }

    // 2、配置重用Cell数据
    NSMutableDictionary*  dict = self.listData[indexPath.row];
    cell.textLabel.text = [dict objectForKey:@"Content"];
    cell.detailTextLabel.text = [dict objectForKey:@"CDate"];
    return cell;
}
-(void)findAll
{

    NSString *path = [[NSString alloc] initWithFormat:@"/kujizu/test01.html"];

    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:@"127.0.0.1:8080" customHeaderFields:nil];
    MKNetworkOperation *op = [engine operationWithPath:path];

    [op addCompletionHandler:^(MKNetworkOperation *operation) {

        NSLog(@"responseData : %@", [operation responseString]);
        NSData *data  = [operation responseData];
        NSDictionary *resDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
        if (data == nil) {

            self.listData = [[NSMutableArray alloc] init];
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"错误信息" message:@"没有数据。" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [alertView show];
        }else{

            NSNumber *resultCodeObj = [resDict objectForKey:@"ResultCode"];
            if ([resultCodeObj integerValue] >=0){

                self.listData = [resDict objectForKey:@"Record"];
                [self.tableView reloadData];
            } else {

                NSString *errorStr = [resultCodeObj errorMessage];
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"错误信息" message:errorStr delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
                [alertView show];
            }
        }

    } errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork请求错误 : %@", [err localizedDescription]);
    }];
    [engine enqueueOperation:op];
}
@end

iOS.访问 Web Service.MKNetworkKit_GET

时间: 2024-10-25 03:55:54

iOS.访问 Web Service.MKNetworkKit_GET的相关文章

iOS.访问 Web Service.MKNetworkKit_POST

#import <UIKit/UIKit.h> #import "T20140628025249NSNumber+Message.h" #import "T20140628025249NSString+URLEncoding.h" #import "MKNetworkEngine.h" #import "MKNetworkOperation.h" @interface T20140628025249ViewCont

iOS.访问 Web Service.同步GET请求方法

1.字符串转换为URL字符串NSString分类 #import <Foundation/Foundation.h> @interface NSString (URLEncoding) -(NSString *)URLEncodedString; -(NSString *)URLDecodedString; @end #import "T20140628013418NSString+URLEncoding.h" @implementation NSString (URLEn

iOS.访问 Web Service.异步GET请求方法

#import <UIKit/UIKit.h> #import "T20140628024750NSNumber+Message.h" #import "T20140628024750NSString+URLEncoding.h" @interface T20140628024750ViewController : UITableViewController<NSURLConnectionDelegate> @property (nonato

iOS.访问 Web Service.异步POST请求方法

#import <UIKit/UIKit.h> #import "T20140628024917NSNumber+Message.h" #import "T20140628024917NSString+URLEncoding.h" @interface T20140628024917ViewController : UITableViewController<NSURLConnectionDelegate> @property (nonato

iOS.访问 Web Service.使用下拉刷新控件

#import <UIKit/UIKit.h> #import "T20140628025702NSNumber+Message.h" #import "T20140628025702NSString+URLEncoding.h" @interface T20140628025702ViewController : UITableViewController @property (nonatomic,strong) NSMutableArray *lis

Java通过Axis访问Web Service

在使用Axis访问Web Service时,需要引入以下包(10个):axis-ant.jar.axis.jar.commons-discovery-0.2.jar.commons-logging-1.0.4.jar.jaxrpc.jar.log4j-1.2.8.jar.saaj.jar.wsdl4j-1.5.1.jar.activation-1.1.jar和mail-1.4.jar. 下面是一段Java代码的例子: 1 package demo; 2 import javax.xml.name

php curl 访问web service接口

利用curl访问web service接口代码如下: $apiUrl = 'http://test.com/test'; $accessToken = '123456789'; $header = ['Authorization: ' . $accessToken,'Content-Type:application/json']; $post = ['sku'=>[]]; $jsonPost = json_encode($post); $ch = curl_init(); curl_setopt

iphone ios 用xcode4.2开发 访问web service的功能

http://blog.csdn.net/panyaorui/article/details/8622990 1.后台利用 cxf 构建一个web service服务. HelloWorld.java [java] view plaincopy /** * */ package com.alcor.jws.test; import javax.jws.WebMethod; import javax.jws.WebService; import org.apache.cxf.feature.Fea

iOS 开发指南 第15章 访问Web Service之REST Web Service

***** 在电脑术语中,统一资源标识符(Uniform Resource Identifier,或URI)是一个用于标识某一互联网资源名称的字符串. 该种标识允许用户对任何(包括本地和互联网)的资源通过特定的协议进行交互操作.URI由包括确定语法和相关协议的方案所定义. Web上可用的每种资源 -HTML文档.图像.视频片段.程序等 - 由一个通用资源标识符(Uniform Resource Identifier, 简称"URI")进行定位. ***** 1 REST Web Ser