我正在尝试向 codeIgniter webservice 发布 POST,但我总是收到相同的消息:
-> [13884:a0b] 从服务器发送的字符串不允许的键字符。
有什么想法吗?谢谢
定义 kUrl@" http://gf.kineth.com/index.php/json_api/ "
这是我的功能
-(void)postMessageLogin:(NSString *)login:(NSString *)pass{//选择登录设备=1;
NSMutableString *postString = [NSMutableString stringWithString:kUrl];
//a = 1 melhor variavel do mundo, faz cenas incriveis
[postString appendFormat:@"loginUser?data={\"email\":\"joao.vitor.pac@gmail.com\",\"password\":\"123456\"}"];
[postString setString:[postString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"%@",postString);
NSString *myRequestString = postString;
NSData *myRequestData = [ NSData dataWithBytes: [ myRequestString UTF8String ] length: [ myRequestString length ] ];
request = [ [ NSMutableURLRequest alloc ] initWithURL: [ NSURL URLWithString:kUrl ] ];
[ request setHTTPMethod: @"POST" ];
[ request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
[ request setHTTPBody: myRequestData ];
NSURLConnection * connection = [[NSURLConnection alloc]
initWithRequest:request
delegate:self startImmediately:NO];
[connection scheduleInRunLoop:[NSRunLoop mainRunLoop]
forMode:NSDefaultRunLoopMode];
[connection start];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)theData{ NSLog(@"从服务器发送的字符串 %@",[[NSString alloc] initWithData:theData encoding:NSUTF8StringEncoding]);
NSError *error;
NSDictionary *dic;
dic = [NSJSONSerialization JSONObjectWithData:theData options:0 error:&error];
NSLog(@"[SL] JsonPost : didReceiveData %@",dic);
NSLog(@"[SL] JsonPost : didReceiveData %@",error);
[connection cancel];
}