1

我从我的网站获取数据:

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。我错在哪里?

4

3 回答 3

2

问题在于希伯来字符,您应该对它们进行 html 转义,也可以尝试使用英文字符请求,看看它是否有效

- (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];
}

AFNetworking 框架AFURLEncodedStringFromStringWithEncoding的函数在哪里

于 2012-08-20T10:38:48.430 回答
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"]];
于 2012-08-20T10:23:08.420 回答
-1

这是因为电子邮件地址中的点。

看这里: 尝试使用 NSURL 访问 Google 翻译时出错

于 2012-08-20T10:45:11.977 回答