Jeff R
Jeff R

Reputation: 1

ASIHttpRequest throws an error and I just can't figure out why

I've been following the examples given at: http://www.iphonedevsdk.com/forum/iphone-sdk-tutorials/76730-webservice-how.html in order to try and get my iphone app to connect to a webservice. However, when I use the following code, it throws me an error:

-(IBAction) startSend:(id)sender
{
    NSURL *url = [NSURL URLWithString:@"mywebsitehere"];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    NSString *xmlString = [NSString stringWithString:@""];
    xmlString=AS(xmlString,@"<id>");
    xmlString=AS(xmlString,@"the id would go here.");
    xmlString=AS(xmlString,@"</id>");
    xmlString=AS(xmlString,@"<Data>");
    xmlString=AS(xmlString,@"Binary Data would be read here.");
    xmlString=AS(xmlString, @"</Data>");
    NSData* xmlData=[xmlString dataUsingEncoding:NSUTF8StringEncoding];

    [request appendPostData:xmlData];

    [request setDidFinishSelector:@selector(requestCompleted:)];
    [request setDidFailSelector:@selector(requestError:)];

    [request setDelegate:self];
    [request startAsynchronous];
}

- (void)requestCompleted:(ASIHTTPRequest *)request
{
    NSString *responseString = [request responseString];
    NSLog(@"%d", responseString);
}


- (void)requestError:(ASIHTTPRequest *)request
{
    NSError *error = [request error];
    NSLog(@"error description : %@", [error localizedDescription]);
}

When I run this, I'll get the error message of: error description : Unable to start HTTP connection.

What would cause it to be unable to start an HTTP connection?

Upvotes: 0

Views: 943

Answers (3)

BigSprocket
BigSprocket

Reputation: 166

I know this is old, but it hasn't been marked as complete yet. I wrestled with this for a while, and it turned out I had dome something like this:

NSString *webserviceBase=@"http://some/url"; NSURL *theUrl = [NSURL URLWithString:[webserviceBase stringByAppendingPathComponent:@"cmd"]];

Note that stringByAppendingPathComponent: mangles the http:// portion of the URL. So, if you're doing something similar, make sure the base includes a trailing slash, and use stringByAppendingString: instead.

Upvotes: 0

highlycaffeinated
highlycaffeinated

Reputation: 19867

You are printing out the address of the error object instead of the object itself. Use this instead:

NSLog(@"The error is: %@", error);

The same goes for the responseString:

NSLog(@"%@", responseString);

Upvotes: 1

lefakir
lefakir

Reputation: 4031

First, Are you sure it is c# ?

Second, you could try

NSLog(@"error description : %@", [error localizedDescription]);

It would be more comprehensive

Upvotes: 0

Related Questions