我使用NSURLConnection
对象从我的服务器下载文件NSMutableRequest
。服务器只返回33
个字节的数据,这是不正确的。我正在制作正确的网址。
-(void)downloadData{
NSURLConnection *connection = nil;
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@,myid=%@&dataid=%@",DOWNLOAD_URL,my_id,data_id]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:30.0];
[request setHTTPMethod:@"GET"];
_myData = [NSMutableData data];
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
NSLog(@"Downloading Failed");
myData = nil;
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
NSLog(@"(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data");
[myData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
NSLog(@"Downloading Finished");
// here you can can save the data in the file.
}
我的回复标题有点像
HTTP 200 No Error
Server: Apache/2.2.26 (Amazon)
X-Powered-By: PHP/5.3.28
Connection: close
TCN: choice
Content-Type: application/octet-stream
Content-Location: fw_download.php
Date: Wed, 09 Apr 2014 06:44:55 GMT
Content-Disposition: filename="abc.xxx"
Content-Length: 730568
Cache-Control: private
Vary: negotiate
有人会告诉我我在这里做错了我应该得到730568
字节,但我只得到33
字节