Iphone 带嵌套字典的HTTP请求

Iphone 带嵌套字典的HTTP请求,iphone,ios,web-services,asihttprequest,asiformdatarequest,Iphone,Ios,Web Services,Asihttprequest,Asiformdatarequest,我需要使用POST方法访问web服务,并使用嵌套字典来接收相关数据。但我总是得到空洞的回应。我做错了什么 NSURL *url = [NSURL URLWithString:@"http://appzander.com/gateway.php"]; ASIFormDataRequest *_request = [ASIFormDataRequest requestWithURL:url]; __weak ASIFormDataRequest *request = _r

我需要使用POST方法访问web服务,并使用嵌套字典来接收相关数据。但我总是得到空洞的回应。我做错了什么

    NSURL *url = [NSURL URLWithString:@"http://appzander.com/gateway.php"];

    ASIFormDataRequest *_request = [ASIFormDataRequest requestWithURL:url];

    __weak ASIFormDataRequest *request = _request;


    AppDelegate *app = [[UIApplication sharedApplication] delegate];
    NSDictionary *paramsDic = [[NSDictionary alloc] initWithObjectsAndKeys:
                             [NSNumber numberWithDouble:app.myLocation.longitude],@"longitude",
                             [NSNumber numberWithDouble:app.myLocation.latitude],@"latitude",
                             @"500000",@"radius",
                             @"1000",@"maxResults",
                             nil];
    NSDictionary *requestDic = [[NSDictionary alloc] initWithObjectsAndKeys:
                                @"GetNearestStations",@"function",
                                @"false",@"debug",
                                paramsDic,@"params",
                                nil];

    [request addRequestHeader:@"Content-Type" value:@"application/json"];
    [request appendPostData:[[SBJsonWriter new] dataWithObject:requestDic]];
    request.requestMethod = @"POST";    
    [request setDelegate:self];
    [request setCompletionBlock:^{         
        NSData *responseString = [request responseData];// responseString];
        NSLog(@"Response: %@", responseString);
        [self plotCrimePositions:responseString];
    }];
    [request setFailedBlock:^{
        NSError *error = [request error];
        NSLog(@"Error: %@", error.localizedDescription);
    }];

    // 6
    [request startAsynchronous];

使用ASIFormDataRequest

     NSURL *url = [NSURL URLWithString:@"yourUrlhere"];   

    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

    [request setRequestMethod:@"POST"];

    [request setPostValue:email forKey:@"username"];

    [request setPostValue:pasw forKey:@"pass"];

    [request setDelegate:self];

    [request startAsynchronous];

已解决-我没有正确发送参数:

 NSURL *url = [NSURL URLWithString:@"http://appzander.com/gateway.php"];

    ASIFormDataRequest *_request = [ASIFormDataRequest requestWithURL:url];

    __weak ASIFormDataRequest *request = _request;


    AppDelegate *app = (AppDelegate*)[[UIApplication sharedApplication] delegate];

    NSDictionary *paramsDic = [[NSDictionary alloc] initWithObjectsAndKeys:
                               [NSNumber numberWithDouble:32.071738],@"longitude",
                               [NSNumber numberWithDouble:34.791295],@"langitude",
                               @"500000",@"radius",
                               @"1000",@"maxResults",
                               nil];

    [request setPostValue:@"false" forKey:@"debug"];
    [request setPostValue:@"GetNearestStations" forKey:@"function"];
    SBJsonWriter *jsonWriter = [[SBJsonWriter alloc] init];

    NSString *paramsDicJSON = [jsonWriter stringWithObject:paramsDic];
   [request setPostValue:paramsDicJSON forKey:@"params"];
    request.requestMethod = @"POST";
    [request setDelegate:self];
    [request setCompletionBlock:^{
        NSString *responseString = [request responseString];
        [self plotBikes:responseString];
    }];
    [request setFailedBlock:^{
        NSError *error = [request error];
        NSLog(@"Error: %@", error.localizedDescription);
    }];
    [request startAsynchronous];

这就是我正在使用的。请看代码。看起来像你的。问题是什么?你没有正确地发送所需的请求。我正在将字典转换为JSON NSData,而不是JSON NSSting