2012-09-14 20 views
10

llamo al servicio web desde mi aplicación ios usando NSURLConnection. Aquí está mi códigoObteniendo dominio de error = NSURLErrorDomain Code = -1004 "No se pudo conectar con el servidor".

#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); 
} 

Su acabar llamando a esta url http://winshark.softwaytechnologies.com/bariodwcfservice/baroidservice.svc/Json/Products/123

pero cuando golpeo esta URL en el navegador de su trabajo bien, pero en mi aplicación im conseguir este error

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

favor ayúdeme lo que podría ser un problema

+0

¿Está probando esto en el dispositivo o en el simulador? – Wasim

+0

ambos no funcionan – sachin

Respuesta

2

Parece que lo está configurando bien, sospecho algo relacionado con sus objetos: intente llamar a una URL codificada reemplazando su correo electrónico xisting solicitud de URL con:

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

Debería hacer la solución de problemas mucho más fácil.

+0

es extraño, no puedo encontrar el método 'requestWithString' en [NSURLRequest class documentation] (https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class /Reference/Reference.html) ... ¿puedes ayudarme por favor? –

+0

Creo que la mejor ayuda que puedo darte es señalarte algún otro buen código SO ;-) echa un vistazo a http://stackoverflow.com/questions/19263186/nsurlrequest-creation-using-query-string-in-ios para ejemplos de solicitudes de URL hechas de esta manera. – woody121

+1

@MaxGontar No hay ninguno. Creo que quiso decir '[NSURLRequest requestWithURL: [NSURL URLWithString: @" ... "]]'. – devios1

Cuestiones relacionadas