[英]How to check POST Request is sended to Server in JSON web service
在我的应用程序中,我想检查登录身份验证。 但是,当我发布请求时,我不知道我的请求是否已到达服务器。
这是我的代码...
-(void)clearsession
{
NSString *username = @"tiger@gmail.com" ;
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=%@"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.