HTTP状态码= 0(iPhone)(目标c)

编程入门 行业动态 更新时间:2024-10-08 10:51:06
本文介绍了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:@"www.example"]]; [request_get2 setHTTPMethod:@"GET"]; [request_get2 setValue:@"text/html; charset=UTF-8" forHTTPHeaderField:@"Content-Type"]; [request_get2 setValue:@"www.example" 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)

本文发布于:2023-10-10 18:06:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479333.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:状态   目标   HTTP   iPhone

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!