ASIHttpRequest登录空响应

时间:2012-02-10 21:05:27

标签: ios ios4 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 ==&gt; (null)
我还使用了[request setValidatesSecureCertificate:NO];
哪里出错了?我还想阅读让我记录的页面。谢谢!

1 个答案:

答案 0 :(得分:0)

您应该从Delegate ...

获取响应和响应数据

这是你的代码:

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]);
}