Я хочу «POST» значение JSON для сервера и отклик json databack.ASIHttpRequest POST JSON хорошо, но AFNetworking не
URL: http://solok.com:8080/soloo/phone/execute?content= {"method": "tet_123", "version", "1"}, может получить правильное значение (JSON) в браузере.
ASIHTTPRequest путь:
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);
}
Он работает гладко! Но AFNetworkding нет, вот код;
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");
}];
Выходные данные: успех <>.
или я использую другой способ 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);
}];
Код ответивший 200, что означает соединение является правильным, но до сих пор не правильный результат. Не знаете, почему. Любая помощь, спасибо заранее!