in my Iphone app i use AFNetworking to POST some data to a webservice and get some data back…
Here is my example, i always get “false” back as response, what i am doing wrong?
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];
EDIT: the method i call in the Url returns a string (no the string is not 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;
}
}
this method i am calling with my iphone and normaly it should return xml or?
You are using a complicated way of building the operation, but it will work.
But it should work, the thing you are missing is assign the XMLparser.
In the documentation of AFXMLRequestOperation is stated.
Also there is not need to make the NSURLRequest via the
AFHTTPClient, you can easily create one you self or use theAFHTTPClientto do the creation of theAFHTTPRequestOperationfor you.To use the AFHTTPClient to just return whatever the server returns :