虽然我得到相同的字符串,但比较似乎有问题。 顺便说一句,我正在使用python来处理服务器端编码,并且它的工作做得很好。
- (void) createAccount:(id)paramSender {
if ([self.loginEmail.text length] > 0 && [self.loginPassword.text length] > 0) {
NSString *urlAsString = @"http://www.somesite.com/cgi-bin/check_email.py";
NSString *newEmail = [NSString stringWithFormat:@"&checkEmail=%@", self.loginEmail.text];
urlAsString = [urlAsString stringByAppendingString:@"?sessionString=session"];
urlAsString = [urlAsString stringByAppendingString:newEmail];
NSURL *url = [NSURL URLWithString:urlAsString];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
[urlRequest setTimeoutInterval:30.0f];
[urlRequest setHTTPMethod:@"POST"];
NSString *body = @"bodyParam1=BodyValue1&bodyParam2=BodyValue2";
[urlRequest setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection
sendAsynchronousRequest:urlRequest
queue:queue
completionHandler:^(NSURLResponse *response,
NSData *data,
NSError *error) {
if ([data length] >0 && error == nil){
NSString *html =
[[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
NSLog(@"%@", html);
if ([html isEqualToString:@"available"]) {
NSLog(@"selam");
}
else {
NSLog(@"no");
}
}
else if ... (rest of the code)
我的输出是(你可以看到返回的字符串,代码中的字符串是相同的):
2013-12-16 16:42:33.992 SomeApp[1191:5107] available
2013-12-16 16:42:33.993 SomeApp[1191:5107] no
更新(python部分):
print "Content-Type: text/html;charset=UTF-8\n"
print "available"