2012-09-14 18 views
10

Ho chiamato il servizio Web dalla mia app ios utilizzando NSURLConnection. Ecco il mio codiceOttieni dominio errore = NSURLErrorDomain Code = -1004 "Impossibile connettersi al server."

#define kBaseServerUrl  @"http://winshark.softwaytechnologies.com/bariodwcfservice/baroidservice.svc/Json/" 

#define kProductServiceUrl @"Products" 

-(void)callService{ 
    NSURL *url; 
    if (currState == ProductServiceState) { 
     url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@/%d",kBaseServerUrl,kProductServiceUrl,[self getRevisionNumberForProduct]]]; 
    } 
    else if(currState == TankStrickerServiceState){ 
     url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@/%d",kBaseServerUrl,kTankStrickerServiceUrl,[self getRevisionNumberForTankStricker]]]; 
    }else if(currState == CalculationServiceState){ 
     url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@/%d",kBaseServerUrl,kCalculationServiceUrl,[self getRevisionNumberForCalculation]]]; 
    }else{ 
     //Future Use 
    } 
    NSLog(@"%@",[url absoluteString]); 
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url]; 
    NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self]; 

    NSLog(@"%@",urlConnection); 
} 

sua fine per chiamare questo URL http://winshark.softwaytechnologies.com/bariodwcfservice/baroidservice.svc/Json/Products/123

ma quando ho colpito questo URL sul browser il suo bel lavoro, ma nella mia app im ottenere questo errore

Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." 

prega aiutami quale potrebbe essere il problema

+0

Lo stai testando sul dispositivo o sul simulatore? – Wasim

+0

è non funzionante – sachin

risposta

2

Sembra che tu lo stia configurando correttamente, sospetto qualcosa riguardo ai tuoi oggetti - prova a chiamare un URL hard coded sostituendo la tua e richiesta dell'URL xisting con:

NSURLRequest *urlRequest = [NSURLRequest 
requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]; 

In questo modo è possibile semplificare la risoluzione dei problemi.

+0

è strano, non riesco a trovare il metodo 'requestWithString' in [NSURLRequest class documentation] (https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class /Reference/Reference.html) ... puoi aiutarmi per favore? –

+0

Penso che il miglior aiuto che posso darti ti indichi un buon altro codice SO ;-) consulta http://stackoverflow.com/questions/19263186/nsurlrequest-creation-using-query-string-in-ios per esempi di richieste URL fatte in questo modo. – woody121

+1

@MaxGontar Non ce n'è uno. Penso che intendesse '[NSURLRequest requestWithURL: [NSURL URLWithString: @" ... "]]'. – devios1

Problemi correlati