在我的应用程序中,我要检查“登录身份验证”。但是,当我发布请求时,我不知道我的请求是否已到达服务器。
这是我的代码...
-(void)clearsession
{
NSString *username = @"[email protected]" ;
NSString *password = @"password";
NSURL *aUrl = [NSURL URLWithString:@"http://developer.b24solutions.com/grocery/MyLogin.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:aUrl
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:0.0];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
NSString *postString = [NSString stringWithFormat:@"username=%@ password=%@",username,password];
NSLog(@"string that post:%@",postString);
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *clearSession = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[clearSession start];
NSLog(@"%@",clearSession);
if(clearSession){
NSLog(@"data send");
}
else
{
NSLog(@"connection failed");
}
}
NSURLConnection方法与定义的相同。
在此应用程序中,我以JSON格式发送用户名和密码。如果用户名已经注册,然后接收响应status=1
,否则status=0
。但是,当我发送注册的用户名和密码时,将收到状态为= 0的响应,为什么会发生这种情况?
上次我检查您是否需要&符。尝试更改此:
@"username=%@ password=%@"
对此:
@"username=%@&password=%@"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句