Problems creating an action for every object in an array - ios

I have run into a strange situation when creating trying to save the objects from an array to a rails backend. I have two array and I have no problem saving each one on its own. The problem is that I am also creating a table that is a combination of the two objects. So it would be best to create an action for index path 1 for both arrays, index path 2 for both arrays and so on. The arrays will always have the same amount of objects inside of them. This way, for index path one, it could save both of them and make the combination table at the same time, thus eliminating my problem. My second problem is that I have no idea how to create a block of code that executes for an index path of multiple array. I know this is probably quite weird, but any help would be great.
Here is how I was doing it for every object of a single array:
-(void)savePeroid {
[self.periodArray enumerateObjectsUsingBlock:^(id object, NSUInteger idx, BOOL *stop) {
if (self.navigationItem.rightBarButtonItem.tintColor == [UIColor redColor]) {
NSURL *url = [NSURL URLWithString:#"http://localhost:3000/"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
object, #"period[name]",
nil];
NSMutableURLRequest *request = [httpClient requestWithMethod:#"POST"
path:#"api/period"
parameters:params];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(#"ID: %#", [JSON valueForKeyPath:#"id"]);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(#"Request Failure Because %#",[error userInfo]);
}];
[operation start];
}
}];
[self saveSubject];
}

How about this:
-(void)savePeroid {
for (int i=0; i<self.periodArray.count; i++) {
id periodObject = self.periodArray[i];
id otherArrayObject = self.otherArray[i];
if (self.navigationItem.rightBarButtonItem.tintColor == [UIColor redColor]) {
NSURL *url = [NSURL URLWithString:#"http://localhost:3000/"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
periodObject, #"period[name]",
otherArrayObject, #"other[something]",
nil];
NSMutableURLRequest *request = [httpClient requestWithMethod:#"POST"
path:#"api/period"
parameters:params];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(#"ID: %#", [JSON valueForKeyPath:#"id"]);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(#"Request Failure Because %#",[error userInfo]);
}];
[operation start];
}
};
[self saveSubject];
}

Related

Converting JSON From AFNetworking

I am using AFNetworking to obtain JSON from a URL, the JSON is parsed and is supposed to be converted into an NSData format which is then in turn put into an array. However it doesn't seem to be working. I think i'm being stupid because it worked previously but now-
-(void)loadFromServer{
NSString *trendsURL = [NSString stringWithFormat:#"http://myurl.com/data.json"];
NSURL *url = [NSURL URLWithString:trendsURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation
JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id json) {
self.results = [json valueForKeyPath:#"data"];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
}];
[operation start];
NSError *anError = nil;
NSArray *parsedElements = [NSJSONSerialization JSONObjectWithData:elementsData
options:NSJSONReadingAllowFragments
error:&anError];
for (NSDictionary *aModuleDict in parsedElements){
MosData *aMosModule = [[MosData alloc] initWithDictionary:aModuleDict];
[elements addObject:aMosModule];
}
}
The data is displayed in a collection like view separately, there is no problem with this separate view as it works when I access data from a file rather than server.
-(void)loadFromDisk{
NSString *pathString = [[NSBundle mainBundle] pathForResource:#"data" ofType:#"json"];
NSData *elementsData = [NSData dataWithContentsOfFile:pathString];
NSError *anError = nil;
NSArray *parsedElements = [NSJSONSerialization JSONObjectWithData:elementsData
options:NSJSONReadingAllowFragments
error:&anError];
for (NSDictionary *aModuleDict in parsedElements){
MosData *aMosModule = [[MosData alloc] initWithDictionary:aModuleDict];
[elements addObject:aMosModule];
}
}
The JSON that is fetched is like so:
{
"imageLink": "http://link.com/image.jpg",
"size": 1,
"title": "Food"
}
I gave it another go, and still it's not working. results is a declared NSArray.
-(void)loadFromServer{
NSString *trendsURL = [NSString stringWithFormat:#"http://url.com/data.json"];
NSURL *url = [NSURL URLWithString:trendsURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation
JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id json) {
NSLog(#"Custom Mosaic: %#", json);
self.results = [json valueForKeyPath:#"data"];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
}];
[operation start];
for (NSDictionary *aModuleDict in self.results){
MosData *aMosModule = [[MosData alloc] initWithDictionary:aModuleDict];
[elements addObject:aMosModule];
}
}
I think the issue might actually be this having played around a little, for some reason, it won't pick up the results of the data parsed in the AFNetworking operation.
-(id)init{
self = [super init];
if (self){
elements = [[NSMutableArray alloc] init];
[self loadFromServer];
}
return self;
}
// WWDC 2012 proposed method
+ (CustomMosDatasource *)sharedInstance {
static CustomMosDatasource *sharedInstance;
if (sharedInstance == nil)
sharedInstance = [CustomMosDatasource new];
return sharedInstance;
}
#pragma mark - MosViewDatasourceProtocol
-(NSArray *)mosElements{
NSArray *retVal = elements;
return retVal;
}
The results of the log is just JSON:
Custom Mosaic: {
data = (
{
imageFilename = "http://distilleryimage6.instagram.com/9969123a6af311e2b6c722000a9d0edd_7.jpg";
size = 1;
title = "Title";
},
AFJSONRequestOperation *operation = [AFJSONRequestOperation
JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id json) {
self.results = [json valueForKeyPath:#"data"];
NSError *anError = nil;
NSArray *parsedElements = [NSJSONSerialization JSONObjectWithData:elementsData
options:NSJSONReadingAllowFragments
error:&anError];
for (NSDictionary *aModuleDict in parsedElements){
MosData *aMosModule = [[MosData alloc] initWithDictionary:aModuleDict];
[elements addObject:aMosModule];
}
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
}];
[operation start];
Your json don't seem to have keyPath "data", remove the valueForKeyPath:#"data", please paste the result of "NSLog(#"Custom Mosaic: %#", json)" in your question.
The operation is asynchronized. The success block is called after the request returns data. Please put code in the success block like this
-(void)loadFromServer{
NSString *trendsURL = [NSString stringWithFormat:#"http://url.com/data.json"];
NSURL *url = [NSURL URLWithString:trendsURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation
JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id json) {
NSLog(#"Custom Mosaic: %#", json);
// your json doesn't have keyPath "data"
self.results = json;
// Codes moved into success block
for (NSDictionary *aModuleDict in self.results){
MosData *aMosModule = [[MosData alloc] initWithDictionary:aModuleDict];
[elements addObject:aMosModule];
}
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
}];
[operation start];
}

AFNetworking POST not working

I am trying to make a POST request using AFNetworking. I went through SO and found that I need to include httpClient.parameterEncoding = AFJSONParameterEncoding
It still doesn't work even after making that change. Anything else I am missing ? Here is the code
NSDictionary *subDictionaryUsers = [[NSDictionary alloc]initWithObjectsAndKeys:myObject.name,#"name", myObject.topic_description,#"description", nil];
NSString *_restPath = [NSString stringWithFormat:#"spaces.json/auth_token=%#",myObject.auth_token];
NSDictionary *params = [[NSDictionary alloc]initWithObjectsAndKeys:subDictionaryUsers,#"space",nil];
myAppAFNClient *httpClient = [myAppAFNClient sharedClient];
NSMutableURLRequest *request = [httpClient requestWithMethod:#"POST" path:_restPath parameters:params];
httpClient.parameterEncoding = AFJSONParameterEncoding;
[httpClient getJsonResponse:request notificationString:#"add.hydramixer.topics"];
myAppAFNClient.m
-(void)getJsonResponse:(NSURLRequest *)_request notificationString:(NSString *)notifString{
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:_request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
if([notifString length] != 0){
// handling success
}
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){
// handling errors
}];
[operation start];
}

AFNetworking POST cannot return json data

I want to make a request with POST method and after that I want them to return the json data or NSDictionary, but they can only return the string when it succeed
Like NSString *response = [operation responseString];
Anyone know how to make them return NSdictionary instead of NSString?
-(IBAction)SubmitLogin:(id)sender{
NSLog(#"Login");
// NSLog(#"%#",username);
//START FUNGSI UNTUK POST, PUT, DELETE
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:signinUrl];
[httpClient defaultValueForHeader:#"Accept"];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
#"someuser", #"username",
#"somepassword",#"password",
nil];
NSMutableURLRequest *request = [httpClient requestWithMethod:#"POST"
path:#""
parameters:params];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
[operation setCompletionBlockWithSuccess:
^(AFHTTPRequestOperation *operation,
id responseObject) {
NSString *response = [operation responseString];
NSLog(#"response: %#",response);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(#"error: %#", [operation error]);
}];
//call start on your request operation
[operation start];
I was trying to send JSON object and getting back JSON data and parse it
NSURL *url = [NSURL URLWithString:#"https://MySite.com/"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc]initWithBaseURL:url];
//[httpClient setParameterEncoding:AFJSONParameterEncoding];
//[httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
#"Ans", #"name",
#"29", #"age", nil];
NSMutableURLRequest *request = [httpClient requestWithMethod:#"POST"
path:#"/testJSONReturn.php"
parameters:params];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(#"DATA: %#", [JSON valueForKeyPath:#"data"]);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(#"Request Failure Because %#",[error userInfo]);
}];
[operation start];
Might help
This is what I use, feel free to fit it to your needs:
-(void) loginWithUserID:(NSString*)usrID User:(NSString*)usr Password:(NSString *)psw Sender:(id)sender
{
if ([sender respondsToSelector:#selector(startLoading)]){
[sender performSelector:#selector(startLoading)];
}
baseURL = [NSString stringWithFormat:
#"http://xxx.xxx.xxx.xxx/test/service.svc/weblogin"];
NSString* serviceURL = [NSString stringWithFormat:
#"%#?userID=%#&user=%#&password=%#",baseURL,usrID,usr,psw;
NSURL *url = [NSURL URLWithString:[serviceURL stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
self.LoginOK = [JSON valueForKeyPath:#"LoginOK"];
if (LoginOK.intValue == 1) {
NSDictionary *usrData = [JSON valueForKeyPath:#"userData"];
userData = [[UserData alloc]init];
[userData readFromJSONDictionary:usrData];
NSLog(#"Userdata: %#",userData);
if ([sender respondsToSelector:#selector(loginSuccessful:)])
{
[sender performSelector:#selector(loginSuccessful:)];
}
}else{
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:#"Error" message:#"No Correct Login Credentials" delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alertView show];
;}
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
if ([sender respondsToSelector:#selector(stopLoading)]){
[sender performSelector:#selector(stopLoading)];
}
[[[UIAlertView alloc] initWithTitle:#"Error"
message:#"Loginservice not available! Check your connection!"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil] show];
NSLog(#"Error: %#", error);
}];
[operation start];
};
EDIT: Oh and use a
-(void)readFromJSONDictionary:(NSDictionary *)d
{
[self setProperty1:[d objectForKey:#"property1"]];
}
method to get all the properties out of that dictionary into a custom class.

AFNetworking with AFHTTPClient with AFJSONRequestOperation // MIME-Type Issues

I've been trying to get a grip on AFHTTPClient in the specific instance of dispatching a request to a REST-based service that requires OAuth authentication. I have no problem with creating the OAuth authentication using GTMOAuth.
I can also successfully marshall parameters to dispatch the request and obtain a well-formed JSON response using a hand-cobbled NSMutableURLRequest and both AFJSONRequestOperation and an NSURLConnection. Those latter two mechanics were my sanity check that I was touching the service correctly.
I get a response using
[AFHTTPClient HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject)]
but no matter what — it's interpreted as text/plain. The returned object's class is __NCFData.
No bueno.
This bit of code doesn't want to return a response that's a dictionary of any sort.
- (IBAction) testFlickr {
// marshall parameters
NSString *urlStr = #"http://api.flickr.com/";
NSURL *url = [NSURL URLWithString:urlStr];
AFHTTPClient *client = [[AFHTTPClient alloc]initWithBaseURL:url];
[client registerHTTPOperationClass:[AFJSONRequestOperation class]];
[client setParameterEncoding:AFJSONParameterEncoding];
NSDictionary *params = [[NSDictionary alloc]initWithObjectsAndKeys:#"json", #"format", #"66854529#N00", #"user_id", #"1", #"jsoncallback", nil];
NSString *path = [[NSString alloc]initWithFormat:#"services/rest/?method=flickr.people.getPhotos"];
NSMutableURLRequest *af_request = [client requestWithMethod:#"GET" path:path parameters:params];
// flickrAuth instance variable is an instance of GTMOAuthAuthentication
[self.flickrAuth authorizeRequest:af_request];
[client setAuthorizationHeaderWithToken:[self.flickrAuth accessToken]];
[client setDefaultHeader:#"Accept" value:#"application/json"];
[client requestWithMethod:#"GET" path:path parameters:params];
LOG_FLICKR_VERBOSE(0, #"Can Authorize? %#", ([self.flickrAuth canAuthorize] ? #"YES":#"NO"));
LOG_FLICKR_VERBOSE(0, #"%#", client);
// first way of trying..
AFHTTPRequestOperation *af_operation = [client HTTPRequestOperationWithRequest:af_request success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSString *str = [[NSString alloc] initWithData:responseObject
encoding:NSUTF8StringEncoding];
LOG_FLICKR_VERBOSE(0, #"Weird af_operation semantics, but.. %#", str);
LOG_FLICKR_VERBOSE(0, #"Weird af_operation semantics returns %#", [responseObject class]);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//
LOG_FLICKR_VERBOSE(0, #"Weird af_operation semantics, error.. %#", error);
}];
[af_operation start];
}
This request goes through okay. The response data itself is what I'd expect, but it is not any kind of dictionary class.
I'd rather keep to using methods of AFHTTPClient (as opposed to, for example, [AFJSONRequestOperation JSONRequestOperationWithRequest]) so I can use AFHTTPClient's Reachability methods and so forth.
Strangely (to me, at least) if I do the request like this:
NSMutableURLRequest *aj_request = [client requestWithMethod:#"GET" path:path parameters:params];
[self.flickrAuth authorizeRequest:aj_request];
AFJSONRequestOperation *aj_operation =
[AFJSONRequestOperation JSONRequestOperationWithRequest:af_request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
LOG_FLICKR_VERBOSE(0, #"AFJSONRequestOperation %#", JSON);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
LOG_FLICKR_VERBOSE(0, #"AFJSONREquestOperation Error %#", error);
}];
[aj_operation start];
It fails with a "401" because it was expecting application/json in the response header and instead thinks it's received text/plain
But, if I do the request like this:
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[[NSURL alloc]initWithString:#"http://api.flickr.com/services/rest/?method=flickr.people.getPhotos&format=json&user_id=66854529#N00&nojsoncallback=1"]];
[self.flickrAuth authorizeRequest:request];
AFJSONRequestOperation *operation =
[AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
LOG_FLICKR_VERBOSE(0, #"Success Flickr =========\n%# %#", JSON, [JSON valueForKeyPath:#"photos.total"]);
/////handler(JSON, nil);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
LOG_FLICKR(0, #"URL Was %#", url);
LOG_FLICKR(0, #"Failed Flickr ==========\n%# %#", error, JSON);
/////handler(nil, error);
}];
[operation start];
It works fine, including nice JSON, dictionary-formed data.
In the first instance, I'm using AFHTTPClient to produce the NSMutableURLRequest. In the second instance, I'm creating the NSMutableURLRequest on my own. In both cases I'm using AFJSONRequestOperation to dispatch the request leaving the only culprit for the problem to (besides myself..) AFHTTPClient.
In the first example that I can get to work, it's not returning JSON-y data.
In the second example AFHTTPClient seems to create an NSMutableURLRequest that blatantly fails — but (AFAICT) the same URL succeeds when that URL is created "by hand" using [NSMutableURLRequest requestWithURL].
I wonder — what am I missing when using AFHTTPClient?
Help?
In your first code example, it looks like you're doing NSMutableURLRequest *af_request = [client requestWithMethod:#"GET" path:path parameters:params]; and then setting default headers afterwards. Default headers only get applied to requests created after they were specified. Maybe that's where things are going amiss.
Also, that 401 error may be complaining about its content type, but 401 is an error status code, meaning that you're unauthenticated.
I ended up removing all the header parameters to isolate the problem, but it made no difference. Examining the response quite closely gave me a clue. While Flickr does return "JSON" it is not Lint-free, it seems and requires a tweak to one of the parameters. I had been sending jsoncallback=1 but it should be nojsoncallback=1. Once I fixed that parameter AFJSONRequestOperation handles the response correctly and parses the JSON.
My final code looks like this (for others, n.b. the nojsoncallback=1 parameter)
- (IBAction)testFlickrAFJSON:(id)sender
{
// marshall parameters
NSString *urlStr = #"http://api.flickr.com/";
NSURL *url = [NSURL URLWithString:urlStr];
//NSDictionary *params = [[NSDictionary alloc]initWithObjectsAndKeys:#"json", #"format", #"66854529#N00", #"user_id", nil];
NSDictionary *params = [[NSDictionary alloc]initWithObjectsAndKeys:#"json", #"format", #"66854529#N00", #"user_id", #"1", #"nojsoncallback", nil];
NSString *path = [[NSString alloc]initWithFormat:#"services/rest/?method=flickr.people.getPhotos"];
AFHTTPClient *client = [[AFHTTPClient alloc]initWithBaseURL:url];
NSMutableURLRequest *af_request = [client requestWithMethod:#"GET" path:path parameters:params];
[self.flickrAuth authorizeRequest:af_request];
LOG_FLICKR_VERBOSE(0, #"Can Authorize? %#", ([self.flickrAuth canAuthorize] ? #"YES":#"NO"));
AFJSONRequestOperation *af_operation_2 = [AFJSONRequestOperation JSONRequestOperationWithRequest:af_request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
LOG_FLICKR_VERBOSE(0, #"AFJSONRequestOperation Alt %#", JSON);
LOG_FLICKR_VERBOSE(0,#"AFJSONRequestOperation Alt response MIMEType %#",[response MIMEType]);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
LOG_FLICKR_VERBOSE(0, #"AFJSONREquestOperation Alt Error %#", error);
NSHTTPURLResponse *resp = [[error userInfo] valueForKey:AFNetworkingOperationFailingURLResponseErrorKey];
LOG_FLICKR_VERBOSE(0,#"AFJSONRequestOperation Alt Error response MIMEType %#",[resp MIMEType]);
}];
[af_operation_2 start];
}

ASIHttpRequest POST JSON well, but AFNetworking is not

I want to "POST" a JSON value to server and response a json databack.
The URL: http://solok.com:8080/soloo/phone/execute?content={"method":"tet_123","version","1"}, can get the right value(JSON) in browser.
ASIHTTPRequest way:
NSDictionary *postDic = [NSDictionary dictionaryWithObjectsAndKeys:#"tet_123",#"method",#"1",#"version",nil];
NSString *postString;
//Then convert the "postDic" to NSString, the value is:{"method":"tet_123","version","1"} assign to postString;
psotString = ...;
ASIFormDataRequest *req=[ASIFormDataRequest requestWithURL:url];
[req setRequestMethod:#"POST"];
[req setPostValue:posStr forKey:#"content"];
[req startAsynchronous];
[req setDelegate:self];
[req setCompletionBlock:^{
NSData *d = [req responseData];
NSLog(#"respond is %#".d);
}
It works smoothly! But AFNetworkding is not, here is the code;
NSURL *url = [NSURL URLWithString:#"http://localhost:8080"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
[httpClient setParameterEncoding:AFJSONParameterEncoding];
NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:#"tet_123",#"method",#"1",#"version",nil];
NSDictionary *dic1 = [NSDictionary dictionaryWithObjectsAndKeys:dic,#"content", nil];
[httpClient postPath:#"/soloo/phone/execute" parameters:dic1 success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSDictionary *d = (NSDictionary *)responseObject;
NSLog(#"success is %#",d);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(#"fail");
}];
The output is: success is <>.
or i use another way of AFNetworking:
NSMutableURLRequest *request = [httpClient requestWithMethod:#"POST"path:#"/soloo/phone/execute" parameters:dic1];
AFJSONRequestOperation *ope = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(#"response %d",response.statusCode);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(#"fail%d JSON %#",response.statusCode,JSON);
}];
The respond code is 200, which means connection is correct, but still no the correct result.
Not sure why. Any help, thank in advance!
The reason is is the backend is a "GET" method, but i did "POST", meanwhile, i forgot: [Operation start] method.

Resources