2012-02-10 74 views
0

我有一個請求我會使用ASIHttpRequest,對於這個頁面我該怎麼辦?ASIHttpRequest登錄空回覆

  <form method="post" action="Login.jsp"> 
      <fieldset> 
       <legend>Insert</legend> 
        <ul> 
         <li><label for="username">User</label><input maxlength="10" id="user" name="username" value=""></li> 
         <li><label for="password">Password</label><input maxlength="16" type="password" id="pwd" name="password" value="" ></li> 
         <li id="errore"> error</li> 
         <li><input type="submit" id="go" value="enter"></li> 

        </ul> 
      </fieldset> 
      </form> 

我必須讓這個:

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"url....Login.jsp"]]; 
[request setRequestMethod:@"POST"]; 
[request setPostValue:@"user" forKey:@"username"]; 
[request setPostValue:@"pass" forKey:@"password"]; 

[request setDelegate:self]; 
[request startSynchronous]; 

NSLog(@"Response %d ==> %@", request.responseStatusCode, [request responseString]); 

,但我得到: 響應0 ==>(null)
我也使用了[request setValidatesSecureCertificate:NO];
錯誤在哪裏?而且我還想閱讀讓我記錄的頁面。謝謝!

回答

0

你應該從委託的響應和responseData ...

這裏是你的代碼:

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"url....Login.jsp"]]; 

[request setRequestMethod:@"POST"]; 
[request setPostValue:@"user" forKey:@"username"]; 
[request setPostValue:@"pass" forKey:@"password"]; 
[request setDelegate:self]; 
[request setDidFailSelector:@selector(PostFailed:)]; 
[request setDidFinishSelector:@selector(PostFinished:)]; 

[request startSynchronous]; 

,並在您的主文件中添加2委託方法:

- (void)PostFailed:(ASIHTTPRequest *)theRequest 
{ 
    //notify user 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Error sending request to the server" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [alert show]; 
    [alert release]; 
} 

- (void)PostFinished:(ASIHTTPRequest *)theRequest 
{ 
    //get here your post response data... 

    NSLog(@"Response %d ==> %@", theRequest.responseStatusCode, [theRequest responseString]); 
} 
+0

我做了這個,但我收到錯誤發送請求。 – Doom 2012-02-10 22:09:55

+0

你確定你的網址是否正確? – 2012-02-11 00:05:16

+0

哪個asihttp委託方法確實被調用?完成或失敗? – Lefteris 2012-02-12 14:34:29