簡體   English   中英

如何檢查POST請求是否以JSON Web服務發送到服務器

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM