1

私のiPhoneアプリでは、AFNetworkingを使用して一部のデータをWebサービスにPOSTし、一部のデータを取得しています...

これが私の例です、私は常に応答として「false」を返します、私が間違っていることは何ですか?

NSURL *baseURL = [NSURL URLWithString:@"http://myPath/Iphone/method"];


    AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
    [httpClient defaultValueForHeader:@"Accept"];

    NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                            [udid copy], @"uuid",
                            nil];


    NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:@"http://myPath/Iphone/method" parameters:params];


    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];


    [httpClient registerHTTPOperationClass:[AFXMLRequestOperation class]];


    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        response = [operation responseString];
        NSLog(@"response: %@",response);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"error: %@", [operation error]);
    }];


    [operation start];

編集:私がURLで呼び出すメソッドは文字列を返します(文字列はfalseではありません)


  [HttpPost]
        public bool checkIphone(string uuid)
        {
           IDictionary<string,object> check  = Request.Properties;

           uuid = check["uuid"].ToString();

           //do anything with the uuid

           if (1<0)
           {
               return true;
           }
           else
           {
               return false;
           }

        }

私がiPhoneで呼び出しているこのメソッドは、通常、xmlまたは?

4

2 に答える 2

5

操作を構築する複雑な方法を使用していますが、うまくいきます。しかし、うまくいくはずです。欠けているのは、XMLparser を割り当てることです。AFXMLRequestOperationのドキュメントに記載されています。

 NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:@"http://myPath/Iphone/method" parameters:params];

AFXMLRequestOperation *operation = [[AFXMLRequestOperation alloc] initWithRequest:request];
operation.responseXMLParser = xmlParser; //Here you should assign an instance of NSXMLParser to handle you XML parsing.

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    response = [operation responseString];
    NSLog(@"response: %@",response);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"error: %@", [operation error]);
}];

また、 を介して NSURLRequest を作成する必要はありませんAFHTTPClient。自分で簡単に作成するか、 を使用してAFHTTPClientを作成することができAFHTTPRequestOperationます。


AFHTTPClient を使用して、サーバーが返すものを返すには:

// Don't include the method here
NSURL *baseURL = [NSURL URLWithString:@"http://myPath/Iphone/"];

AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
[httpClient defaultValueForHeader:@"Accept"];

NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                        [udid copy], @"uuid",
                        nil];

[httpClient postPath:@"method" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
    // reponseObject will hold the data returned by the server.

}failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error retrieving data: %@", error);
}];
于 2012-08-08T11:53:54.317 に答える
-1

ここにタイプミスがありますか?[udid copy], @"uuid",

于 2012-08-08T20:59:09.413 に答える