2013-01-17 37 views
0

我目前正试图从ASIHttpRequest切换到MKNetworkKit和Im有问题的发布数据。如何在MKNetworkKit中执行以下操作? ASIHTTPRequest * request = [ASIHTTPRequest requestWithURL:url];} ASIHTTPRequest * request = [ASIHTTPRequest requestWithURL:url]; ASIHTTPRequest * request = [ASIHTTPRequest requestWithURL:url]; ASIHTTPRequest * request = [ASIHTTPRequest requestWithURL:url];MKNetworkKit如何添加发布数据

[request appendPostData:[[NSString stringWithFormat:@“{\”version \“:%@,\”values \“:[{\”device \“:\”%@ \“,\”os \ “:\”ios \“,\”version \“:\”%@ \“}]}”,VERSION,[[UIDevice currentDevice] uniqueIdentifier],[[UIDevice currentDevice] systemVersion]] dataUsingEncoding:NSUTF8StringEncoding]];

我只是不确定如何在MKNetworkKit中追加发布数据。我找到了addData方法,但是这不允许我将上面的数据与值中的额外数据相加。{}

有谁知道如何?

回答

-1

尽管我在这方面颇为新颖,但让我与大家分享我正在做的事情。

首先,我创建引擎(我调用的服务位于哪里)。

在我的界面:

@interface INGMainViewController(){ 
    MKNetworkEngine *engine_; 

} 

在我的初始化:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 

    { 
     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
     if (self) { 
      engine_= [[MKNetworkEngine alloc] initWithHostName:@"www.xxx.gr"]; 
      // Custom initialization 
     } 
     return self; 
    } 
在功能

然后,我会打电话给服务:

NSDictionary *formParams = [NSDictionary dictionaryWithObjectsAndKeys: 
          theClientCode, @"ClientCode", 
          theContractNumber, @"ContractCode", 
          theAppleID, @"AppleID", 
          @" ", @"AndroidID", 
          @" ", @"WindowsID", 
          uid, @"AppleDeviceID", 
          @" ", @"AndroidDeviceID", 
          @" ", @"WindowsDeviceID", 
          theCellPhone, @"TelephoneNumber" 
          , nil]; 

    MKNetworkOperation *operation = [self.engine operationWithPath:@"/services/Authentication.ashx" 
                  params: formParams 
                 httpMethod:@"POST"]; 


    [operation addCompletionHandler: 
    ^(MKNetworkOperation *operation) 
    { 
     NSLog(@" Operation succeds: %@", [operation responseString]); 
    } 
         errorHandler:^(MKNetworkOperation *errorOperation, NSError *error) 
         { 
          NSLog(@" Errors occured: %@", error); 
         }]; 
    [self.engine enqueueOperation:operation]; 
} 

...那是全部。

当然,我仍然要面对一些问题,但我认为这里并没有来自Kit。

我希望我帮你。

0

试试这个:

MKNetworkOperation *op = [self operationWithPath:INIT_URL params:body httpMethod:@"POST" ssl:YES]; 
[op setPostDataEncoding:MKNKPostDataEncodingTypeJSON];//This is important 
[op addCompletionHandler:^(MKNetworkOperation *completedOperation)