- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
大家好,我知道以前问过这种问题,但我没有从他们那里得到任何解决方案在我的项目中,当我将代码放在登录按钮上时,我在登录 View 中工作时出现错误
Error : Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo=0x7fb37b62c9a0 {NSLocalizedDescription=unsupported URL, NSUnderlyingError=0x7fb37b715a20 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -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);
请帮助我解决它我已经看到类似类型的问题但没有解决这个问题感谢任何帮助
最佳答案
我试过你的代码。除了你的 url 之外,其他代码行都是正确的。如果你传递了正确的 URL,它将完美运行。
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://eyeforweb.info.bh-in-15.webhostbox.net/myconnect/api.php"]]; //pass your url here
[request setHTTPMethod:@"POST"];
//Passing The String to server
NSString *strUserId = @"pradeep.kumar@eyeforweb.com";
NSString *strPassword = @"admin123";
NSString *userUpdate =[NSString stringWithFormat:@"login=%@&password=%@",strUserId,strPassword, nil];
//Check The Value what we passed
NSLog(@"the data Details is %@", userUpdate);
//Convert the String to Data
NSData *data1 = [userUpdate dataUsingEncoding:NSUTF8StringEncoding];
NSLog(@"The postData is - %@",data1);
//Apply the data to the body
[request setHTTPBody:data1];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
if(httpResponse.statusCode == 200)
{
NSError *parseError = nil;
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError];
NSLog(@"The response is - %@",responseDictionary);
NSInteger success = [[responseDictionary objectForKey:@"success"] integerValue];
if(success == 1)
{
NSLog(@"Login SUCCESS");
}
else
{
NSLog(@"Login FAILURE");
}
}
else
{
NSLog(@"Error");
}
}];
[dataTask resume];
关于IOS:kCFErrorDomainCFNetwork 错误 -1002。错误域=NSURLErrorDomain 代码=-1002 "unsupported URL",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39510552/
最近几天我尝试从 d00m 调试网络错误。我开始用尽想法/线索,我希望其他 SO 用户拥有可能有用的宝贵经验。我希望能够提供所有相关信息,但我个人无法控制服务器环境。 整个事情始于用户注意到我们应用程
注意:这个问题还没有答案! 我使用 UIWebView 加载以下 URL: https://buchung.salonmeister.de/ort/301655/menue/#offerId=9076
当我在 Xcode 中运行我的应用程序时,我收到 NSURLErrorDomain: -1003。我还没有在 StackOverflow 上看到这个错误,有任何线索吗?我正在使用 Alamofire
我发布这个主要是为了引用,因为我永远找不到需要的列表! NSURLErrorDomain 是否有规范的代码含义列表? 最佳答案 取自here ,错误码列表如下: NSURLErrorUnknown =
我是 iOS 开发新手。我正在尝试加载一个 JSON,这是我的函数: func loadmyJSON (urlPath: String) { let url: NSURL = NSU
这是我第一次开发 iOS 应用程序。我正在尝试使用 Facebook 图形 API 发布一些数据。我不断收到以下错误: The operation couldn’t be completed. (NS
我正在使用 IOS 13.3,我的应用程序在 6 个月后突然停止。 我检查了我的证书,发现证书没有问题。 我收到以下错误。 NSURLSession/NSURLConnection HTTP loa
我在使用 TWRequest API 发送推文回复时遇到问题。我能够成功发布新推文/状态,但回复失败并出现以下错误。请指教 我在回复帖子中收到的错误是: Error Domain=NSURLError
我试图将图片下载到我的应用程序 请求失败,错误为 NSURLErrorDomain,代码实际上是 -1100。该网址应该是正确的,因为我在浏览器中检查过它。有人知道为什么吗? let userImag
我需要从受密码保护的 URL 解析 xml 文件,我尝试了以下操作 NSURLCredential *credential = [NSURLCredential credentialWithUser:
我已经在我的应用程序中使用 fb-connect 对我的用户进行了身份验证,然后当用户单击某处时,我在 webview 中打开一个 facebook 应用程序 URL,但在打开它之前,我收到一条错误消
这个问题已经有答案了: 已关闭10 年前。 Possible Duplicate: How do I fix NSURLErrorDomain error -999 in iPhone 3.0 OS
我的请求崩溃“域 NSURLErrorDomain 代码 4294966292”。 let request = NSMutableURLRequest(URL: NSURL(string: IPPos
我尝试发送同步请求并收到以下错误。 Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is inval
我是初学者,在手机上部署我的应用程序时遇到问题。该应用程序在模拟器上运行良好,但当我在手机上运行并尝试在手机上发送注册表时,出现以下错误 FAILURE: Error Domain=NSURLErro
我正在尝试按以下方式连接 Bluemix 远程数据库: IMFDataManager.sharedInstance().remoteStore("people", completionHandler:
在连接关闭(wifi 和蜂窝网络关闭)的情况下测试我的应用程序时,我能够捕捉到错误。但是,在 Xcode 控制台中,我也可以看到错误消息。我的代码没有将这些打印到控制台。这些应该出现吗?我可以忽略它们
尝试使用 iOS 应用程序(NSUrlSession、AFNetworking-2)连接到 SOAP Web 服务。Webservice 使用 http 和 https(不是自签名证书)工作正常。现在
我在一年多前开发了一个应用程序,为用户提供照片共享和视频共享。它运行没有任何问题,直到几周前我引入了一个新功能:将视频标记为仅在 WiFi 可用时上传的可能性:视频设置为使用 NSURLSession
我想在我的 XCode5.0 中添加存储库。当我尝试连接 svn 存储库时,它没有连接并给出错误,如“操作无法完成。(NSURLErrorDomain 错误 -1012。)”。那你能建议我做什么吗?
我是一名优秀的程序员,十分优秀!