ASIHTTPRequest Failed to create request (bad url?) Error

I keep getting: Failed to create request error message (bad url?) On request, for example:


- (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 am a "VERY" newbie to Objective-C ...

thank

-Brad

+3
source share
1 answer

Change -startAsynchronousto -startSynchronousand delete the line in which you set the request delegateto self. Asynchronous means that it is running in the background, in which case you need to use delegate methods. Since you put everything in one method, you want to use a synchronous request.

Edit

Initialize the URL as follows:

[NSURL URLwithString: [@"http://..." stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding]]
+4

Source: https://habr.com/ru/post/1765432/


All Articles