Search code examples
objective-ciosxmlasihttprequest

ASIHTTPRequest error bad URL


I've been searching for this problem for a while now. I'm trying to update the value of xml node with ASIHTTPRequest. This code should send a request but it always returns me:

Error Domain=ASIHTTPRequestErrorDomain Code=5 "Unable to create request (bad url?)"

So I've tried to encode my URL like many answers on this site and others proposed and nothing worked so far... I've tried this :

stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding

as well as this one :

CFURLCreateStringByAddingPercentEscapes

I've also tried this :

NSString *urlString = @"http://192.168.123.143:50003/Courbe.xml"; 
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL urlWithString:urlString]];

And I'm always getting the same error. This is the code I'm trying to run:

NSString *url = @"http://192.168.123.143:50003/Courbe.xml"; 
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setRequestMethod:@"POST"];
[request addPostValue:@"111" forKey:@"tempset"];
[request setDelegate:self];
[request startSynchronous];

Those are my delegate methods:

- (void)requestFinished:(ASIHTTPRequest *)request
- (void)requestFailed:(ASIHTTPRequest *)request

Anyone can help me solve this?


Solution

  • requestWithURL: requires an NSURL as a parameter, but you are passing an NSString.

    Try using this corrected code:

    NSString *urlString = @"http://192.168.123.143:50003/Courbe.xml"; 
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL urlWithString:urlString]];