Делегат NSURLconnection не вызывается

Мои делегаты NSURLConnection не получают вызова. Я пытаюсь сделать это вместо того, чтобы использовать [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[[NSURL URLWithString: urlAddress] host]]; это запрещено для магазина приложений.

NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
myError.hidden = FALSE;
NSHTTPURLResponse   * response;
NSError             * error;
NSMutableURLRequest * request;
NSString            * params;
NSString *urlAddress = [NSString stringWithFormat:@"%@/?action=request&api=json&module=ManagementModule&function=startSession&instance=0",[ConnectServer returnserverip]];
NSLog(@"UPX %@",[ConnectServer returnserverip]);
NSLog(@"IP %@",[ConnectServer returnclientip]);
if([defaults boolForKey:@"enablePincode"]){
    NSString *account = [defaults stringForKey:@"myAccount"];
    NSString *username =[defaults stringForKey:@"myUsername"];
    NSString *password = [defaults stringForKey:@"myPassword"];
    NSString *clientip = [ConnectServer returnclientip];
    NSString *clientname = [ConnectServer returnclientname];
    params = [[[NSString alloc] initWithFormat:@"params=&auth[password]=%@&auth[mode]=%@&auth[account]=%@&auth[user]=%@&auth[rights]=%@&auth[user_ip]=%@&auth[client_name]=%@",password,@"password",account,username,@"user",clientip,clientname] autorelease];

request = [[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlAddress] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60] autorelease];
NSData *myRequestData = [params dataUsingEncoding:NSUTF8StringEncoding];
//[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[[NSURL URLWithString: urlAddress] host]];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:myRequestData];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d", [myRequestData length]] forHTTPHeaderField:@"Content-Length"];
request.URL = [NSURL URLWithString:urlAddress];
error       = nil;
response    = nil;
NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
>>>>>>NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self ];
>>>>>>[connection start];
NSLog(@"The server saw:\n%@", [[[NSString alloc] initWithData:data encoding: NSASCIIStringEncoding] autorelease]);
NSLog(@"Parameters: %@", params);
NSLog(@"Actual sended parameters to the server: %@", myRequestData);
NSString *Sresponse;

person Oblieapps    schedule 17.09.2011    source источник


Ответы (1)


1- убедитесь, что вы делегируете себя, и я думаю, что вы это делаете. 2-также убедитесь, что вы не используете другой поток, такой как NSOperationINvocation .. 3- при выполнении вышеуказанного кода убедитесь, что вы можете попробовать

[самостоятельное выполнениеselectoratmainthread: @selecor (функция:) withObject: Object];

NSString *ips = [NSString stringWithFormat:@"http://10.0.0.0:2552/NewsAccessService.asmx"];
    NSString *soapMessage = [NSString stringWithFormat:
                             @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                             "<SOAP-ENV:Envelope \n"
                             "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n"
                             "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n" 
                             "xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" \n"
                             "SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" \n"
                             "xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"> \n"
                             "<SOAP-ENV:Body> \n"
                             "<GetAlbumPhotos xmlns=\"http://tempuri.org/\"/> \n"
                             "</SOAP-ENV:Body> \n"
                             "</SOAP-ENV:Envelope>"];
    NSURL *url = [NSURL URLWithString:ips];
    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];                         
    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];              
    [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [theRequest addValue: @"http://tempuri.org/GetAlbumPhotos" forHTTPHeaderField:@"Soapaction"];
    [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
    [theRequest setHTTPMethod:@"POST"];     
    [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
    NSURLConnection *theConnection = [[[NSURLConnection alloc] initWithRequest:theRequest delegate:self] autorelease];
    if(theConnection) {
        webData = [[NSMutableData data] retain];
        AlbumPhotos = [[NSMutableArray alloc] init];
        x = 1;
        return x;
    }

обращаться с делегатами, такими

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    [webData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [webData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    //NSLog(@"Connection failed: %@", [error description]);

}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    [connection release];
    NSString *responseString = [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding];
}
person Mina Nabil    schedule 17.09.2011
comment
зачем вам отправлять sendSynchronousRequest - person Mina Nabil; 17.09.2011