HTTP状态码= 0(iPhone)(目标c) [英] HTTP status code = 0 (iPhone) (objective c)

查看:133
本文介绍了HTTP状态码= 0(iPhone)(目标c)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一下iPhone应用程序目标C问题.

I want to ask about the iPhone application objective C problem.

我编写了一个程序来存储cookie,并传递到另一个URL来检索cookie. 但是,我发现返回状态代码之一为0.html的内容为空.

I wrote a program to store the cookies and pass to another URL to retrieve the cookies. However, I found that one of the return status code is 0. The content of the html is empty.

有人可以帮助我吗? 以下是我的代码.

Can any one help me? The following is my code.

// create a new mutable url
 NSMutableURLRequest *request_get2 = [[[NSMutableURLRequest alloc] init] autorelease];
    [request_get2 setURL:[NSURL URLWithString:@"http://www.example.com"]];  
 [request_get2 setHTTPMethod:@"GET"];
 [request_get2 setValue:@"text/html; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
 [request_get2 setValue:@"http://www.example.com" forHTTPHeaderField:@"Referer"];
 [request_get2 setHTTPShouldHandleCookies:YES];
        // cookiesString is a string, the format is "cookieName=cookieValue;"
 [request_get2 setValue: (NSString *) cookiesString forHTTPHeaderField:@"Cookie"];

 // doGet - response
 NSHTTPURLResponse *response_get2 = nil;
 NSError *error_get2 = nil;
 NSData *responseData_get2 = [NSURLConnection sendSynchronousRequest:request_get2 returningResponse:&response_get2 error:&error_get2];
 NSString *data_get2 = [[NSString alloc]initWithData:responseData_get2 encoding:NSUTF8StringEncoding];


 NSString *responseURL_get2 = [[response_get2 URL] absoluteString];           // null value
 NSString *responseTextEncodingName_get2 = [response_get2 textEncodingName];  // null value
 NSString *responseMIMEType_get2 = [response_get2 MIMEType];                  // null value
 NSUInteger *responseStatusCode_get2 = [response_get2 statusCode]; //[responseStatusCode intValue]; // the status code is 0

非常感谢

推荐答案

如果获得响应代码的0,则响应response_get2可能从未初始化,这可能表明与请求无关的问题您的Web服务器.

If you get a 0 for a response code, the response response_get2 probably was never initialized, which might point to a problem with the request unrelated to your web server.

您设置了error_get2,因此在下达请求后检查其值:

You set error_get2, so check its value after the request is placed:

if (!error_get2) {
    NSString *responseURL_get2 = [[response_get2 URL] absoluteString];           // null value
    NSString *responseTextEncodingName_get2 = [response_get2 textEncodingName];  // null value
    NSString *responseMIMEType_get2 = [response_get2 MIMEType];                  // null value
    NSUInteger *responseStatusCode_get2 = [response_get2 statusCode]; //[responseStatusCode intValue]; // the status code is 0
}
else {
    NSLog(@"something went wrong: %@", [error_get2 userInfo]);
}

这篇关于HTTP状态码= 0(iPhone)(目标c)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆