Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying To Send Multipart/Form Data in Objective-C, To µTorrent's Web API
    primarykey
    data
    text
    <p>I've been trying to get this code working to send a torrent's data to the µTorrent Web API, unfortunately, as far as I can tell, nobody has ever tried to make a .torrent file handler for µTorrent in Objective-C before, which isn't all that surprising.</p> <p>I have this code here at the moment, but I invariably get the error message: "Error: torrent file content not supplied in form parameter".</p> <pre><code>NSMutableURLRequest * request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?token=%@&amp;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]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload