网址可能会注明获取网络数据响应 [英] url could note get web data response

查看:72
本文介绍了网址可能会注明获取网络数据响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

          I am trying to hit this url with json parsing but when i hit with breakpoint there is no data in nslog..

在另一个解析中,它可以正常工作,但是使用此网址,它不起作用 字符串格式值为:-kk,8882121456,2015-10-26,123,123,male,02

In the another parsing it works perfectly but with this url it not works String format values are :-kk,8882121456,2015-10-26,123,123,male,02

NSString * urlLoc = @" http://www.vallesoft.com/vlcc_api/bookappointment. php ;

NSString *urlLoc = @"http://www.vallesoft.com/vlcc_api/bookappointment.php";

            NSString *requestString = [NSString stringWithFormat:@"name=%@&mobileno=%@&emailid=%@&dob=%@&password=%@&gender=%@&ref=%@&fbflag=0",goSignUpName,goSignUpMobile,goSignUpEmailId,goSignUpDOB,goSignUpPassword,goSignUpGender,goSignUpReferenceId] ;
            NSData *postData = [requestString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
            NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];
            NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

            [request setURL:[NSURL URLWithString:urlLoc]];
            [request setHTTPMethod:@"POST"];
            [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
            [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
            [request setHTTPBody:postData];

            [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
             {

                 if(data.length>0 && connectionError==nil)
                 {


                     responseData = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
                     NSLog(@"LOGIN Response ==> %@", responseData);

                     if ([responseData intValue] == 1)
                     {

                         UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"Thanks" message:@"Registered" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
                         [alert show];

                         for(id controller in [self.navigationController viewControllers])
                         {
                             if([controller isKindOfClass : [ViewController class]]){ [self.navigationController popToViewController: controller animated: YES];
                                 break;
                             }
                         }



                     }
                     else if ([responseData intValue] == 2)
                     {
                         UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"Already Reegistered" message:@"Please choose other Details" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
                         [alert show];
                     }
                     else if (responseData==NULL)
                     {
                         UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"Alert!" message:@"Not Book Try Again!!" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
                         [alert show];
                     }

推荐答案

好吧,我正在使用以下代码作为虚拟对象并将其工作.您可以尝试以下操作:

Well, I am using the following code for doing it as dummy and it works. You can try it as follow:

NSString *urlLoc = @"http://www.vallesoft.com/vlcc_api/bookappointment.php";

NSString *requestString = [NSString stringWithFormat:@"name=harsh&mobileno=8882121782&emailid=hkrajput12@gmail.com&date=2015-10-21&cityname=1&centrename=3&servicename=5&expertname=3&timeslot=15:00 TO 16:00&cuser=hkrajput12@gmail.com&cdate=2015-10-21&timeslotid=15"];

NSData *postData = [requestString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

    [request setURL:[NSURL URLWithString:urlLoc]];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];

[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
             {

                 if(data.length>0 && connectionError==nil)
                 {


                     NSString *responseData = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
                     NSLog(@"LOGIN Response ==> %@", responseData);

                 }

}];

这篇关于网址可能会注明获取网络数据响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆