简体   繁体   English

如何检查POST请求是否以JSON Web服务发送到服务器

[英]How to check POST Request is sended to Server in JSON web service

In my app I want to check the Authentication For Login. 在我的应用程序中,我想检查登录身份验证。 But when I post request I don't know if my request has reached the server. 但是,当我发布请求时,我不知道我的请求是否已到达服务器。

Here is my code... 这是我的代码...

 -(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");
}
}

and rather NSURLConnection method are same as defined. NSURLConnection方法与定义的相同。

In this app I send the username and password in a JSON format. 在此应用程序中,我以JSON格式发送用户名和密码。 If the user name is already register then it receives response status=1 otherwise status=0 . 如果用户名已经注册,那么它将收到响应status=1否则status=0 but when I send registered username and password then the response will be received as status=0 why is this happening? 但是,当我发送注册的用户名和密码时,系统将以状态= 0接收到响应,为什么会发生这种情况?

Last time I checked you need the ampersand. 上次我检查您是否需要&符。 Try changing this: 尝试更改此:

@"username=%@ password=%@"

To this: 对此:

@"username=%@&password=%@"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM