【发布时间】:2014-06-05 19:24:30
【问题描述】:
我之前将NSStrings 变成了NSURL,它总是只是[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]。
现在,我发生了一件非常奇怪的事情。我有 not 为空的数据(来自 NSURLSessionDataTask)。就像我打印出来一样,我会得到字节的数据。
然后,当我尝试将其转换为 NSString 并将其注销时,它显示为 null。真的很奇怪。
这是一个sn-p:
NSMutableURLRequest *getProgressReportRequest = [[NSMutableURLRequest alloc] initWithURL:curURL];
[getProgressReportRequest setHTTPMethod:@"GET"];
NSLog(@"The request is %@", [getProgressReportRequest URL]);
NSURLSessionDataTask *getProgressReportTask = [defaultSession dataTaskWithRequest:getProgressReportRequest completionHandler:^(NSData *getProgressReportData, NSURLResponse *getProgressReportResponse, NSError *getProgressReportError) {
if ([getProgressReportData length] > 0 && getProgressReportError == nil) {
NSLog(@"some html is %@", [[NSString alloc] initWithData:getProgressReportData encoding:NSUTF8StringEncoding]);
} else NSLog(@"Some error with the getting progress report %@", getProgressReportError);
}];
[getProgressReportTask resume];
【问题讨论】:
-
您在控制台中得到了什么,NSLog 消息?
-
2014-06-05 15:36:47.767 Zangle[1613:389139] some html is (null) 2014-06-05 15:36:48.308 Zangle[1613:389139] some html is (null) 2014-06-05 15:36:48.847 Zangle[1613:389139] some html is (null) 2014-06-05 15:36:49.351 Zangle[1613:389139] some html is (null) 2014-06-05 15:36:52.629 Zangle[1613:389139] some html is (null) 2014-06-05 15:36:57.723 Zangle[1613:389139] some html is (null) -
如果你可以发送网址,我会为你测试它&你确定http方法应该是GET而不是POST。
标签: ios objective-c nsstring nsdata