我正在使用一个以 json 对象作为参数的 web 服务。这是我的代码:
    -(void)createHttpHeaderRequest {
        NSString *x = @"{\"GetVehicleInventory\": {\"ApplicationArea\": {\"Sender\": {\"ComponentID\":}}}" (something like that)
        NSString *sample = [NSString stringWithFormat:@"https://trialservice.checkitout?XML_INPUT=%@",x];
 NSString * final = (NSString *) CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)sampleReq, NULL, CFSTR(":/?#[]@!$&'()*+,;=\""), kCFStringEncodingUTF8);
 NSMutableRequest *request = [NSMutableREquest requestWithURL:[NSURL URLWithString:final]];
    NSURLConnection * theConnection = [[NSURLConnection alloc]initWithRequest:theRequest delegate:self];
        if (theConnection) {
            NSLog(@"Service hit");
        }
    }
    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
        NSError * error;
        NSDictionary * dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
        NSArray * categories = [dict objectForKey:@"category"];
        [self.delegate giveControlBackToController:categories];
    }
当我尝试 NSLog 示例时,它会为我提供完整的 URL,粘贴到浏览器中会返回结果,但是当我在请求上调用 NSLog 时,它显示为 null,此后什么也没有发生。控件永远不会转到其 NSURLConnection 委托方法。