Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASIHTTPRequest Unable to create request (bad url?) Error

I keep getting: Unable to create request (bad url?) error message on a request like:


- (void)grabURLInBackground :(id)sender 
{
    NSURL *url= [NSURL URLWithString:@"http://api.website.com/api_requests/standard_request/getItemRequest={\"Id\":\"Logic\"}"];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request addRequestHeader:@"X-WEBSITE-API-DEV-NAME" value:@"cghjm"];
        [request setDelegate:self];
    [request startAsynchronous];
}


- (void)requestFinished:(ASIHTTPRequest *)request
{
   // Use when fetching text data
   NSString *responseString = [request responseString];
   NSLog(responseString);
}

- (void)requestFailed:(ASIHTTPRequest *)request
{
   NSError *error = [request error];
    NSLog(@"%@:%s Error: %@", [self class], _cmd, [error localizedDescription]);
}

I'm "VERY" new to Objective-C...

Thanks

-Brad

like image 752
Brad Avatar asked Dec 16 '25 19:12

Brad


1 Answers

Change -startAsynchronous to -startSynchronous and remove the line where you set the request's delegate to self. Asynchronous means that it runs in the background, in which case you need to use the delegate methods. Since you've put everything in one method, you want to use a synchronous request.

Edit

Initialize the URL like this:

[NSURL URLwithString: [@"http://..." stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding]]
like image 83
Alexsander Akers Avatar answered Dec 19 '25 12:12

Alexsander Akers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!