【发布时间】:2016-09-15 12:02:09
【问题描述】:
你好,我知道以前问过这类问题,但我没有从他们那里得到任何解决方案 在我的项目中,当我将代码放在登录按钮上时,我正在登录视图中工作,但出现错误
错误:错误域=NSURLErrorDomain 代码=-1002“不支持的 URL” UserInfo=0x7fb37b62c9a0 {NSLocalizedDescription=不支持的 URL, NSUnderlyingError=0x7fb37b715a20 "操作无法完成。 (kCFErrorDomainCFNetwork 错误 -1002.)"}
但我使用的登录代码与我在以前的项目中使用的代码相同,并且在那里运行良好
这是我的代码:
-(IBAction)login:(id)sender
{
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
NSURL *url = [NSURL URLWithString:@"http://eyeforweb.info.bh-in-15.webhostbox.net/myconnect/api.php?token={LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUc4d0RRWUpLb1pJaHZjTkFRRUJCUUFEWGdBd1d3SlVBeWo0WE9JNjI4cnJRTG9YeEpXNG1zUWI1YmtvYk1hVQpzMnY1WjFKeXJDRWdpOVhoRzZlZk4rYTR0eGlMTVdaRXdNaS9uS1cyL1NCS2pCUnBYUzVGYUdiV0VLRG1WOXkvCkYrWHhsUXVoeER0MEV3YkRBZ01CQUFFPQotLS0tLUVORCBQVUJMSUMgS0VZLS0tLS0K}&method=user.getLogin"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
[request addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request addValue:@"*/*" forHTTPHeaderField:@"Accept"];
[request setHTTPMethod:@"POST"];
NSString *mapData = [NSString stringWithFormat:@"login=abc@gmail.com&password=123456"];//,username.text, password.text];
NSData *postData = [mapData dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
[request setHTTPBody:postData];
NSLog(@"map data is = %@",mapData);
NSURLSessionDataTask * postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * data, NSURLResponse* response, NSError * error) {
if(error == nil)
{
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSString *text = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog(@"Data = %@",text);
NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSLog(@"jsondic= %@",jsonDic);
NSDictionary *userDataDic = [jsonDic objectForKey:@"data"];
NSLog(@"Dict is %@",userDataDic);
请帮我解决它我已经看到类似类型的问题,但没有从这个问题中克服 任何帮助表示赞赏
【问题讨论】:
-
阿比你的网址不正确
-
但它在 Advance rest 客户端中给出了正确的响应
-
当我运行你的代码时它给了我 nil
-
另外,您的用户名错误,因为您的登录名中有 2 个用户 id(login=abc@gmail.com@eyeforweb.com)。这怎么可能?
-
它给出的响应如下: { "api": { "total": 1 "current_page": "" }- "output": [2] 0: true 1: { "user_id": " 1" "email": "@.com" "user_name": "admin"
标签: ios objective-c json parsing nsurlerrordomain