这个问题与另一个有关:Zend getParameters not return what is in url route
我面临的问题是,Zend 服务器随机没有获取路由中的参数,导致我的应用程序登录崩溃。即,有时在打印getParams();
功能时,我会收到以下用户电子邮件:
Array (
[email] = user@email.com
(...)
)
这工作正常,但有时我得到这个:
Array (
[user@email.com] = 2.874983 //Longitude
(...)
)
导致登录操作崩溃。
这可能是服务器端或客户端的故障。每次调用服务器时,我都会打印一个,并且我已经看到请求 url 的格式总是正确NSLog
的。NSMutableURLRequest
也许这是一个巧合,我不知道,但有时试图解决这个问题我已经更改了请求代码并暂时修复了它。但是,在一些请求之后,错误又回来了。
以下代码段代表我用来连接服务器的代码:
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[self._url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
NSMutableString *values = nil;
if ( params ) {
NSDictionary *parameters = params;
values = [[NSMutableString alloc] init];
for ( NSString* key in parameters ) {
NSMutableString *value = [[NSMutableString alloc] init];
[value appendString:key];
[value appendString:@"="];
[value appendString:[self urlEncodeValue:[parameters valueForKey:key]]];
[value appendString:@"&"];
[values appendString:value];
}
}
NSData *postData = [values dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *postLenght = [NSString stringWithFormat:@"%d", [postData length]];
if ( cookies ) {
NSDictionary *cooks = cookies;
for ( NSString* cookie in cooks) {
NSMutableString *ck = [[NSMutableString alloc] initWithString:cookie];
[ck appendString:@"="];
[ck appendString:[cooks valueForKey:cookie]];
[theRequest addValue:ck forHTTPHeaderField:@"Cookie"];
}
}
[theRequest setHTTPMethod:self._method];
if ( values ) {
[theRequest setValue:@"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest setHTTPBody: postData];
[theRequest setValue:postLenght forHTTPHeaderField:@"Content-Length"];
}
// create the connection with the request
// and start loading the data
NSLog(@"%@", theRequest);
NSURLConnection *theConnection =[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
另一个重要的事情是登录会发送纬度和经度值,当其中一些值发生变化时,它似乎会崩溃。