私は、このコードを機能させて torrent のデータを µTorrent Web API に送信しようとしてきましたが、残念ながら、私が知る限り、Objective-C で µTorrent 用の .torrent ファイル ハンドラを作成しようとした人はいません。それほど驚くべきことではありません。
現時点ではこのコードがありますが、常に次のエラー メッセージが表示されます。「エラー: torrent ファイルのコンテンツがフォーム パラメータに指定されていません」。
NSMutableURLRequest * request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?token=%@&action=add-file", [self getBaseURL], token]]];
NSString * boundary = @"!@!@!@!@!@!@!@!@!";
NSMutableData * body = [NSMutableData alloc];
NSData * torrentFileContents = [[NSFileManager defaultManager] contentsAtPath:fileName];
[request setHTTPMethod:@"POST"];
[request setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary] forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary] forHTTPHeaderField:@"enctype"];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Type: %@\r\n\r\n", @"application/x-bittorrent"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"torrent_file\"; filename=\"%@\"\r\n", fileName] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Length: %ld\r\n", [torrentFileContents length]] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:torrentFileContents]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];