我有執行查詢的URL。在使用網絡傳遞的GET方法中傳遞參數
https://<BASE_URL>/<TENANT_URL>/?query=where UserName='abc'&companyId=&page=1&pageSize=25&filterResultByColumns=true
我正在逃離租戶網址這樣後的剩餘部分,
NSString *requestUrl = [[NSString stringWithFormat:@"%@/?query=where UserName='%@'&companyId=&page=1&pageSize=25&filterResultByColumns=true",<TENANT_URL>,userCredential.userName]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
requestUrl = [NSString stringWithFormat:@"%@/%@",baseurl,requestUrl];
這是我的GET請求。
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
AFHTTPResponseSerializer *serializer = [AFHTTPResponseSerializer serializer];
serializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
manager.responseSerializer = serializer;
manager.requestSerializer = [AFJSONRequestSerializer serializer];
NSString *path = [NSString stringWithFormat:@"%@",URL];
[manager GET:path parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSError* error = nil;
NSArray* json = [NSJSONSerialization
JSONObjectWithData:responseObject
options:kNilOptions
error:&error];
success(json);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
failure(error);
}];
但我總是收到400錯誤的請求錯誤。我認爲問題在於「query = where ..」。但我不確定。我如何解析URL。我在Chrome中使用「POSTMAN」進行測試。它完美的作品。但是當我運行應用程序時,它會引發錯誤。
錯誤:
Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: bad request (400)" UserInfo=0xb7ac2b0 {NSErrorFailingURLKey=https://<BASE_URL>/<TENANT_URL>/?query=where UserName='abc'&companyId=&page=1&pageSize=25&filterResultByColumns=true&url=https%3A%2F%2F<BASE_URL>%2F%2F<TENANT_URL>%2F%3F?query=where%2DUserName%3D%27abc%27%26companyId%3D%26page%3D1%26pageSize%3D25%26filterResultByColumns%3Dtrue, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0xb7e6910> { URL: https://<BASE_URL>/<TENANT_URL>/?query=where UserName='abc'&companyId=&page=1&pageSize=25&filterResultByColumns=true&url=https%3A%2F%2F<BASE_URL>%2F%2F<TENANT_URL>%2F%3F?query=where%2DUserName%3D%27abc%27%26companyId%3D%26page%3D1%26pageSize%3D25%26filterResultByColumns%3Dtrue } { status code: 400, headers {
"Cache-Control" = private;
"Content-Length" = 0;
"Content-Type" = "text/html";
Date = "Fri, 17 Jan 2014 05:29:56 GMT";
Server = "Microsoft-HTTPAPI/2.0";
"X-AspNet-Version" = "4.0.30319";
"X-Powered-By" = "ASP.NET";
} }, NSLocalizedDescription=Request failed: bad request (400)}
http://stackoverflow.com/a/18573417/2439156 –
您發佈的錯誤似乎表明您沒有將實際值放入您的網址 - 它顯示:https:////?query = where UserName ='abc'&companyId =&page = 1&pageSize = 25&filterResultByColumns = true&url = https%3A%2F%2F %2F%2F %2F%3F?query = where%2DUserName%3D%27abc%27%26companyId %3D%26page%3D1%26pageSize%3D25%26filterResultByColumns%3Dtrue',它不包含任何真正的網址。你確定你將你創建的URL傳遞給AFNetworking嗎? –
是的,它有真實的網址。我在這裏發佈了虛擬URL。我瀏覽鉻的網址。它似乎工作。但是當我在模擬器上運行它。我收到這個錯誤。 –