2017-08-02 3 views
0

私はユーザー用のフォームを持っています。それを埋めると、ユーザーは送信ボタンをクリックし、そのデータはサーバーに送信されます。私は応答がnullになるが、フォームからのデータが正常にサーバーに送信されるという問題が発生しています。私は問題がどこに来るのか分からない。私は応答が来たら別の関数を実行したい。私のコードはこれです:IOSのPOSTメソッドの問題

NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration]; 
    NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]]; 

    NSString *[email protected]"My URL"; 


    NSURL * url = [NSURL URLWithString:urlLinkA]; 

    NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:url]; 

    NSString *parameters = [NSString stringWithFormat:@"%@",Parameter]; 


    NSLog(@"parameter %@",parameters); 
    [urlRequest setHTTPMethod:@"POST"]; 

    [urlRequest setHTTPBody:[parameters dataUsingEncoding:NSUTF8StringEncoding]]; 

    NSURLSessionDataTask * dataTask =[defaultSession dataTaskWithRequest:urlRequest 
                 completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 
                  [_indicator stopAnimating]; 
                  _indicator.hidden=YES; 
                  NSLog(@"Response:%@ %@\n", response, error); 

                  NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error]; 

                  NSLog(@"DDD %@",dictionary); 

                  NSString *userid = [dictionary valueForKey:@"property_id"]; 
                  NSLog(@"UserID: %@", userid); 



                  NSLog(@"Response: %@", dictionary); 

                  if ([dictionary isEqual:@""]) { 
                   [self Images]; 
                  } 

                  HomePageViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"]; 
                  [self.navigationController pushViewController:presales animated:YES]; 

                  NSString *[email protected]"Successfully Registered"; 

                  UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Success" 
                                  message:msg 
                                preferredStyle:UIAlertControllerStyleAlert]; 

                  [self presentViewController:alert animated:YES completion:nil]; 

                  int duration = 2; // duration in seconds 

                  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, duration * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ 
                   [alert dismissViewControllerAnimated:YES completion:nil]; 
                  }); 

                 }]; 


    NSLog(@"network error :"); 
    [dataTask resume]; 
} 
+1

あなたのアプリにNSTransportセキュリティを追加しましたか? –

+0

はい。 @ Anbu.Karthik –

+0

あなたがここで得た結果は何ですか?NSLog(@ "Response:%@%@ \ n"、response、error); ' –

答えて

1

お使いのブラウザで郵便配達やRestClientで試してみて、あなたのポストの要求をデバッグしてください、サーバがあなたに適切な応答を送信していない可能性があるかもしれません。 https://restlet.comからダウンロードできます。