输入接口URL能得到值,POST请求返回的值为空
展开全部
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self CellTaxiTextForStarting:@"beijing" andDestination:@"Bibb" andUid:131];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)CellTaxiTextForStarting:(NSString *)theStarting andDestination:(NSString *)theDestination andUid:(int)theUid{
NSString
*URLString=[NSString
stringWithFormat:@"http://1.82.230.175/2014/20140409_dd/api.php/Index/jcBySkInputAddress/fromAddress/%@/address/%@/uid/%d",theStarting,theDestination,theUid];
NSError *error = nil;
NSData *rest=[self synHttpPost:URLString ParamName:@"" ParamValue:nil];
NSDictionary *jsonData = [NSJSONSerialization JSONObjectWithData:rest options:NSJSONReadingMutableLeaves error:&error];
NSLog(@"%@",jsonData);
int YesOrNo=[jsonData[@"YesOrNo"] intValue];
NSString *a=jsonData[@"info"];
NSLog(@"%d:%@",YesOrNo,a);
}
//同步post请求
- (id)synHttpPost:(NSString *)urlAsString ParamName:(NSString *)bodyParam1 ParamValue:(NSString *)bodyValue1{
NSURL *url = [NSURL URLWithString:urlAsString];
__block NSString *resault=@"";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
[urlRequest setTimeoutInterval:30];
[urlRequest setHTTPMethod:@"GET"];
// NSString *body =bodyParam1;
// body = [body stringByAppendingString:@"="];
// body= [body stringByAppendingString:[NSString stringWithFormat:@"%@",bodyValue1]];
// [urlRequest setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:urlRequest
returningResponse:&response
error:&error];
if ([data length] > 0 &&
error == nil){
resault = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
}
else if ([data length] == 0 &&
error == nil){
resault=nil;
}
else if (error != nil){
resault=nil;
}
return data;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询