开发者

ASIFormDataRequest NULL response

开发者 https://www.devze.com 2023-01-22 10:41 出处:网络
i have simply form request in my Obj-c code, which calls a PHP code from my server ASIFormDataRequest *req = [[ASIHTTPRequest alloc] initWithURL:url];

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 U开发者_开发问答ser-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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消