views:

430

answers:

2

Hi,

I have PHP script link, which responds YES or NO when we set post userName and emailID. I have used ASI framework.

When I try to connect with the following code, I get a null return.

NSURL *url = [NSURL URLWithString:@"https://abc.com/abctest/registration.php"];
ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:url];
[request setPostValue:@"[email protected]" forKey:@"email"];
[request setPostValue:@"pqr" forKey:@"userName"];
[request start];
NSError *error = [request error];
if (!error) {
    NSString *response = [request responseString];
    printf("\n\n\n Responce %s",[response UTF8String]);
    response = [response stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    if ([response isEqualToString:@"YES"])
    {
       printf("\n\n YES");
    }
}

I also tried delegates methods setDidFailSelector and setDidFinishSelector ...that time setDidFailSelector get called that means it fail to proceed request....where I am getting wrong????

+1  A: 

From what I understand, don't you have to set the delegate of this request to some class, and then override requestFinished, requestFailed methods to process the reply?

Tejaswi Yerukalapudi
A: 

Since your using a 3rd party class, you're probably better off asking this question on the
ASIHTTPRequest forum where people have special knowledge of this code in particular.

I don't know anything about this class/framework but since it connects over a URL, I do know that it is almost impossible for a check immediately after the posting of a request to have any value. It takes only microseconds for all this code to run and by the time you ask the request if it has any value, the actual packets containing the request haven't even made it to the server much less been processed and returned.

As noted by Tejaswi Yerukalapudi, this class almost certainly has a delegate with methods that it calls only after it has received a response from the server. You should put your printing of the response in that delegate method.

TechZen
I tried delegates methods setDidFailSelector and setDidFinishSelector ...that time setDidFailSelector get called that means it fail to proceed request....where I am getting wrong???
iSwap
I don't know what your error is as I have never worked with this library. I just know any URL based request takes time and you have to wait for a response. Again, you're better off asking on the ASIHTTPRequest forum. Otherwise, you'll have to wait for someone on Stackoverflow who just happens to have used this same non-standard library.
TechZen
Are you sure that your server is processing the request? You should check the server side and make sure that is working before looking at you're client side.
TechZen