Search code examples
afnetworkingafnetworking-2

AFHTTPRequestOperationManager urlstring encoding & Invalid parameter not satisfying: URLString


I'm loading json with afnetworking 2.0:

NSString *weatherUrl = @"http://www.souche.com/pages/xx/xx.json?request_message={\"type\":\"car-subdivision\"}";
weatherUrl = [weatherUrl stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:weatherUrl parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

console error:

 'Invalid parameter not satisfying: URLString'

Is there need url encoding?

but i do it like this:

NSString *weatherUrl = @"http://www.souche.com/pages/dicAction/loadRootLevel.json?request_message={%22type%22:%22car-subdivision%22}";

still error!

How can i do?


Solution

  • It looks like there are a number of issues with the URL you're constructing, and the way you're passing (or not passing) parameters into AFNetworking. You don't need to construct your query string yourself, as AFNetworking will do that for you. As mentioned in my comment above, passing query=where UserName='abc' as part of a URL seems like a bad idea. However, here's a quick example of how you'd call AFNetworking's GET method if your URL was slightly different:

    URL format: https:////?username=abc&companyId=&page=1&pageSize=25&filterResultByColumns=true

    you try this code :D