-1

I am trying to receive a JSON response in iPhone simulator using localhost web service.

I turned on Web sharing and placed the php file named "readmain.php" in /Library/WebServer/Documents

When i write "http://localhost/readmain.php" in Chrome, I see the result displayed perfectly.

But when I try to receive the response in my app, an error is received.

I am using ASIHTTPRequest

Here's the code:

NSURL *url = [NSString stringWithFormat:@"%@%@", HJServerAddress, @"readmain.php"];
DLog(@"request URL = %@", [url description])
self.httpRequest = [ASIHTTPRequest requestWithURL:url];
self.httpRequest.delegate = self;
[self.httpRequest startAsynchronous];
[self.activityIndicator startAnimating];

Where HJServerAddress is: #define HJServerAddress @"http://localhost/"

Whenever the above piece of code executes, I get response from as failed in:

   - (void)requestFailed:(ASIHTTPRequest *)request
   {
       DLog(@"error: %@", [request.error description])
       ULog(@"Failed to load data")
   }

In Logs I get:

2012-09-24 17:44:06.153 _APPNAME_[1798:f803] -[HJHomeViewController fetchAddsJson] [Line 122] request URL = "http://localhost/readmain.php"
2012-09-24 17:44:46.457 _APPNAME_[1798:f803] -[HJHomeViewController requestFailed:] [Line 478] error: Error Domain=ASIHTTPRequestErrorDomain Code=10 "NSInvalidArgumentException" UserInfo=0x69656e0 {NSLocalizedFailureReason=-[__NSCFString absoluteURL]: unrecognized selector sent to instance 0xb650510, NSUnderlyingError=0x6960460 "The operation couldn’t be completed. (ASIHTTPRequestErrorDomain error 10.)", NSLocalizedDescription=NSInvalidArgumentException}

I had also tried to use the IP address of my MAC instead of using "localhost".

I tried accessing the file from iOS simulator's Safari and the response was received successfully.

I am unable to receive the response in my underdevelopment app. Am I doing something wrong in my code? Or is there something more to be done?

Thanks!

Abdullah Umer
  • 4,234
  • 5
  • 36
  • 65

1 Answers1

2

You assign NSString object to NSURL.

pronvit
  • 4,169
  • 1
  • 18
  • 27