1

我在使用ASIFormDataRequest. 该请求似乎已发出,但是当我在完成后尝试访问该请求时出现EXC_BAD_ACCESS错误。环顾四周后,我看不出我在做什么,因此我转向这里。谁能发现我做错了什么?

我在这里得到了代码的基础知识。

- (void)viewDidLoad
{
    /* Stuff here */
    NSURL *url = [NSURL URLWithString:@"http://www.mysite.com/login"];
    ASIFormDataRequest *request1 = [ASIFormDataRequest requestWithURL:url];
    [request1 setPostValue:@"email@email.com" forKey:@"email"];
    [request1 setPostValue:@"pass123" forKey:@"password"];
    [request1 setDelegate:self];
    [request1 startAsynchronous];
}

- (void)requestFinished:(ASIHTTPRequest *)thisRequest
{    
    NSLog(@"Request FInished: %@", thisRequest.responseStatusCode); //crashes here

    if (thisRequest.responseStatusCode == 403){
        NSLog(@"403 Not authorised");
    }
    if (thisRequest.responseStatusCode == 200)
    {
        NSLog(@"Data: %@", thisRequest.responseString);
    }
}
4

1 回答 1

1

问题不是请求不好,而是您试图将 int 打印为对象。改变这个:

NSLog(@"Request FInished: %@", thisRequest.responseStatusCode);

对此

NSLog(@"Request FInished: %d", thisRequest.responseStatusCode);

NSLog(@"Request FInished: %@", thisRequest);(如果您想打印完整的请求描述)

您实际上是在说“在地址 0xresponseStatusCode 处打印对象”,这不是一个有效的对象。

于 2012-02-15T22:19:20.793 回答