如何从RESTUR的NSURLSessionResumeCurrentRequest添加来自HTMLHeaderField的值?

时间:2014-11-12 00:12:35

标签: ios nsurlrequest nsurlsession nsurlsessiondownloadtask header-fields

我有来自cancelByProducingResumeData的resumeData的字典:如下所示,我想知道如何使用NSURLSessionResumeCurrentRequest为HTMLHeaderField添加值。

我想知道如何将NSURLSessionResumeCurrentRequest的NSData转换为NSURLRequest。

  

2014-11-11 13:11:30.545 xxxxXXXXX [77997:14163248] resumeInfo => {      NSURLSessionDownloadURL =" http://xxx.xxx.xxx/webdav/content/admin/201407/ttp.mp4&#34 ;;      NSURLSessionResumeBytesReceived = 50737920;      NSURLSessionResumeCurrentRequest = LT; 62706c69 73743030 d4010203 0405067a 7b582476 65727369 6f6e5824 6f626a65 63747359 24617263 68697665 72542474 6f701200 0186a0af 101c0708 3f404647 4e4f5051 52535435 55566667 68696a6b 6c6d6e6f 70755524 6e756c6c df101b09 0a0b0c0d 0e0f1011 12131415 16171819 1a1b1c1d 1e1f2021 22232425 26272829 252b2c2d 272f2726 26262435 36263826 3a263c3d 3e532431 32522433 53243235 53243137 52243453 24323153 24313356 24636c61 73735224 35532431 38522436 53243232 53243134 52243753 24313953 24313052 24385224 30532431 35532432 33522439 53243131 52243153 24323453 24313652 24325324 32308008 80028000 80078003 800e8002 801b8006 800c8007 800f8007 80008000 80008008 1002800a 80008009 80001009 8000800b 1016800d 08d34110 42264445 574e532e 62617365 5b4e532e 72656c61 74697665 80008005 80045f10 62687474 703a2f2f 63646e2e 6e73752e 736d6172 746b6964 732e7561 6e67656c 2e636f6d 3a383038 302f7765 62646176 2f746f6d 6f2f636f 6e74656e 742f6164 6d696e2f 32303134 30372f74 7470616e 6770616e 675f303 1 5f666f72 416c6c2e 6d7075d2 48494a4b 5a24636c 6173736e 616d6558 24636c61 73736573 554e5355 524ca24c 4d554e53 55524c58 4e534f62 6a656374 23404e00 00000000 00100009 10042300 00000000 00000023 00000000 00000000 13ffffff FFFFFFFF ff534745 54d35758 10595f65 574e532e 6b657973 5a4e532e 6f626a65 637473a5 5a5b5c5d 5e801080 11801280 138014a5 60616263 64801580 16801780 18801980 1a555261 6e676556 41636365 70745f10 0f416363 6570742d 4c616e67 75616765 5849662d 52616e67 655f100f 41636365 70742d45 6e636f64 696e675f 100f6279 7465733d 34323732 33323430 2d532a2f 2a55656e 2d75735f 10203431 32323034 36396464 30643736 31653333 31323537 35316433 38366439 62315d67 7a69702c 20646566 6c617465 d2484971 725c4e53 44696374 696f6e61 7279a273 745c4e53 44696374 696f6e61 7279584e 534f626a 656374d2 48497677 5c4e5355 524c5265 71756573 74a27879 5c4e5355 524c5265 71756573 74584e53 4f626a65 63745f10 0f4e534b 65796564 41726368 69766572 d17c7d54 726f6f74 80010008 0011001a 0023002d 00320037 0056005c 00950099 009c00a0 00a400a7 00ab00af 00b600b9 00bd00c0 00c400c8 00cb00cf 00d300d6 00d900dd 00e100e4 00e800eb 00ef00f3 00f600fa 00fc00fe 01000102 01040106 0108010a 010c010e 01100112 01140116 0118011a 011c011e 01200122 01240126 0128012a 012c012e 01300131 01380140 014c014e 01500152 01b701bc 01c701d0 01d601d9 01df01e8 01f101f3 01f401f6 01ff0208 02110215 021c0224 022f0235 02370239 023b023d 023f0245 02470249 024b024d 024f0251 0257025e 02700279 028b029d 02a102a7 02ca02d8 02dd02ea 02ed02fa 03030308 03150318 0325032e 03400343 03480000 00000000 02010000 00000000 007e0000 00000000 00000000 00000000 034a&gt ;;      NSURLSessionResumeEntityTag = 41220469dd0d761e33125751d386d9b1;      NSURLSessionResumeInfoLocalPath =" /Users/Library/Developer/CoreSimulator/Devices/0F13C2EC-4B9C-4FB4-AD78-7A309C4C65F2/data/Containers/Data/Application/28925A91-9DDE-4041-A1F5-A35387E9115E/tmp/CFNetworkDownload_NKJuq1.tmp& #34 ;;      NSURLSessionResumeInfoVersion = 1;      NSURLSessionResumeOriginalRequest = LT; 62706c69 73743030 d4010203 0405064d 4e582476 65727369 6f6e5824 6f626a65 63747359 24617263 68697665 72542474 6f701200 0186a0ad 07083334 3a3b4243 44454647 4855246e 756c6cdf 1015090a 0b0c0d0e 0f101112 13141516 1718191a 1b1c1d1e 1f20211f 23242520 20282828 1e2c2d20 28303132 53243132 52243353 24313752 24345324 31335624 636c6173 73522435 53243138 52243653 24313452 24375324 31395324 31305224 38522430 53243135 52243953 24313152 24315324 31365224 32800880 02800780 03800280 0c800680 0b800780 07800080 00800080 08100280 09800780 00100980 0a101008 d3350e36 28383957 4e532e62 6173655b 4e532e72 656c6174 69766580 00800580 045f1062 68747470 3a2f2f63 646e2e6e 73752e73 6d617274 6b696473 2e75616e 67656c2e 636f6d3a 38303830 2f776562 6461762f 746f6d6f 2f636f6e 74656e74 2f61646d 696e2f32 30313430 372f7474 70616e67 70616e67 5f30315f 666f7241 6c6c2e6d 7075d23c 3d3e3f5a 24636c61 73736e61 6d655824 636c6173 73657355 4e535552 4ca24041 554e5355 524c584e 534f626a 65637423 404e00 00 00000000 10000923 00000000 00000000 23000000 00000000 0013ffff FFFFFFFF ffffd23c 3d494a5c 4e535552 4c526571 75657374 a24b4c5c 4e535552 4c526571 75657374 584e534f 626a6563 745f100f 4e534b65 79656441 72636869 766572d1 4f505472 6f6f7480 01000800 11001a00 23002d00 32003700 45004b00 78007c00 7f008300 86008a00 91009400 98009b00 9f00a200 a600aa00 ad00b000 b400b700 bb00be00 c200c500 c700c900 cb00cd00 cf00d100 d300d500 d700d900 db00dd00 df00e100 e300e500 e700e900 eb00ed00 ef00f000 f700ff01 0b010d01 0f011101 76017b01 86018f01 95019801 9e01a701 b001b201 b301bc01 c501ce01 d301e001 e301f001 f9020b02 0e021300 00000000 00020100 00000000 00005100 00000000 00000000 00000000 000215&gt ;;      NSURLSessionResumeServerDownloadDate ="星期五,25七月2014 04:36:22 GMT&#34 ;;

1 个答案:

答案 0 :(得分:4)

我尝试使用以下代码更改我的请求,非常成功! ;)

- (NSData *)regenerateResumeData:(NSData *)originData
{
    NSString *error;
    NSPropertyListFormat format;
    NSMutableDictionary* plist = [NSMutableDictionary dictionaryWithDictionary:[NSPropertyListSerialization propertyListFromData:originData mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&error]];

    NSData *currentRequest = [plist objectForKey:@"NSURLSessionResumeCurrentRequest"]; 
    NSURLRequest *request = [(NSURLRequest *)[NSKeyedUnarchiver unarchiveObjectWithData:currentRequest] copy];
    NSMutableURLRequest *mutableRequest = [request mutableCopy];
    [mutableRequest addValue:[plist objectForKey:@"NSURLSessionResumeEntityTag"] forHTTPHeaderField:@"If-Match"];
    [mutableRequest addValue:[NSString stringWithFormat:@"bytes=%@-", [plist objectForKey:@"NSURLSessionResumeBytesReceived"]] forHTTPHeaderField:@"Range"];
    request = [mutableRequest copy];

    NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject:request];

    [plist removeObjectForKey:@"NSURLSessionResumeCurrentRequest"];
    [plist setValue:archivedData forKey:@"NSURLSessionResumeCurrentRequest"];

    return [NSPropertyListSerialization dataFromPropertyList:plist format:NSPropertyListBinaryFormat_v1_0 errorDescription:&error];
}