简体   繁体   中英

ASIFormDataRequest NULL response

i have simply form request in my Obj-c code, which calls a PHP code from my server


ASIFormDataRequest *req = [[ASIHTTPRequest alloc] initWithURL:url];
[req setPostValue:[NSString stringWithFormat:@"%f",slat] forKey:@"mylat"];
[req setPostValue:[NSString stringWithFormat:@"%f",slng] forKey:@"mylng"];
[req start];
NSLog(@"response -",[req responseString]);
[req release];

am not getting the response in the NSLog, but it runs very fine with stringWithContentsOfURL, and i can see the out put in the browser. even i changed the ASIFormDataRequest to ASIHTTPRequest and added User-Agent, but nothing works out. i checked it in different versions of SDKs also, 3.0, 3.1.2, 4.0, 4.1. but no response

I am sure the response from the server is fine,

one more sad thing is that, the same ASI code runs fine on my office network (AIRTEL Broadband) and not in my home which has a BSNL broadband, hope its not a service provider issue.

Did any one find such an issue..

instead of:

[req start]

Try:

[req startSynchronous]

Normally it is fine to manually call -start on an NSOperation object, but in this case, ASIHTTPRequest explicitly provides a -startSynchronous method, so there is probably a good reason to use it.

Try...

ASIFormDataRequest *req = [[ASIHTTPRequest alloc] initWithURL:url];
[req setPostValue:[NSString stringWithFormat:@"%f",slat] forKey:@"mylat"];
[req setPostValue:[NSString stringWithFormat:@"%f",slng] forKey:@"mylng"];

 [req startSynchronous];
  NSError *error = [req error];
  if (!error) {
      NSLog(@"response -",[req responseString]);
  }
[req release];

Finally i got the answer the Proxy is the problem, if you find the same issue, just check with the proxies in your network settings, i don know abt windows, am on MAC so its jus a chekbox to make it happen and the code i hv used ( for safety purpose )

ASIFormDataRequest *req = [[ASIFormDataRequest alloc] initWithURL:url];
[req setDelegate:self];
[req startAsynchronous];
NSError *error = [req error];
if (!error) {
    NSLog(@"response -",[req responseString]);
}
[req release];
[url release];
- (void)requestFinished:(ASIHTTPRequest *)request
{
// Use when fetching text data
NSString *responseString = [request responseString];
NSLog(@"response %d-%@",[responseString length],responseString);
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}

- (void)requestFailed:(ASIHTTPRequest *)request
{
NSError *error = [request error];
NSLog(@"error - %@\n",error);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM