我从我的网站获取数据:
NSString *website = [NSString stringWithFormat:@"http://www.mysite.com/fbconnect.php?email=%@&name=%@&pass=***", nameTrimmmed, [jsonObject objectForKey:@"email"]];
NSLog(@"%@", website);
NSError *error = nil;
NSString *contents = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:website] encoding:NSUTF8StringEncoding error:&error];
内容有Cocoa错误256.我哪里错了?
答案 0 :(得分:2)
问题在于希伯来字符,你应该html-escape他们,也可以尝试用英文字符请求,看它是否有效
- (void)yourMethod
{
NSString *name = @"שימרגוליס";
name = AFURLEncodedStringFromStringWithEncoding(name, NSUTF8StringEncoding);
NSString *website = [NSString stringWithFormat:@"http://www.ba-cafe.com/fbconnect.php?email=%@&name=%@&pass=SwHyK17!",@"email@mail.com",name];
NSLog(@"%@", website);
NSError *error = nil;
NSString *contents = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:website] encoding:NSUTF8StringEncoding error:&error];
}
其中AFURLEncodedStringFromStringWithEncoding
是来自AFNetworking framework
答案 1 :(得分:0)
检查控制台日志中的NSLog(@"%@", website);
你会看到这样的事情:
http://www.mysite.com/fbconnect.php?email=thetrimmedname&name=emailaddress&pass=***
这样做:
NSString *website = [NSString stringWithFormat:@"http://www.mysite.com/fbconnect.php?email=%@&name=%@&pass=***", [jsonObject objectForKey:@"email"], nameTrimmmed ];
而不是:
NSString *website = [NSString stringWithFormat:@"http://www.mysite.com/fbconnect.php?email=%@&name=%@&pass=***", nameTrimmmed, [jsonObject objectForKey:@"email"]];
答案 2 :(得分:-1)
这是因为电子邮件地址中的点。
看看这里: Error while trying to access Google translate with NSURL