开发者

Using NSURLConnection WebService

i get the follwing error below when i run the program given below

Error: Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0x5948b80 {NSUnderlyingError=0x5948ac0 "bad URL", NSLocalizedDescription=bad URL}

wat i need to do plz suggest me

thank u..

the code is given below

@implementation WebSampleViewController


- (void)viewDidLoad
{
    [super viewDidLoad];

    dataWebService = [[NSMutableData data] retain];


    NSMutableURLRequest *request = [[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@" http://www.googleapis.com/customsearch"]] retain];


    NSURLConnection *myConnection = [NSURLConnection connectionWithRequest:request delegate:self];

    [myConnection start];    

    [super viewDidLoad];
}



- (void)connection:(NSURLConnection *)connection di开发者_高级运维dReceiveResponse:(NSURLResponse *)response 
{

    [dataWebService setLength:0];

}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{

    [dataWebService appendData:data];

}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 

{

    NSString *responseString = [[NSString alloc] initWithData:dataWebService encoding:NSUTF8StringEncoding];

    NSLog(@"Response: %@",responseString);

    [responseString release];

    [dataWebService release];

}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{

    NSLog(@"Error during connection: %@", [error description]);
}


You should not retain request instance of type NSMutableURLRequest.

You have an leading white space in your String URL.

Use the below code .

NSMutableURLRequest *request = [[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.googleapis.com/customsearch"]];

I think, you should check your URL , I give the same "Not Found" as on iPhone.


Try it without the space at the beginning of your URL string.


You have to remove whitespace in your url

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜