0

我正在尝试向 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];

}

4

2 回答 2

0

_URI 中不允许使用字符

配置/config.php

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-()';

于 2013-09-20T17:45:29.273 回答
0

我在发送 json 发布数据时遇到了同样的问题,发现这是因为我没有在 http 请求中指定内容类型。

我将此参数添加到我的 URLRequest() 并解决了问题,抱歉我也无法在 ObC 中回答,但希望这对将来的人有所帮助

迅捷3

request.addValue("application/json", forHTTPHeaderField: "Content-Type")
于 2017-11-30T14:21:14.983 回答