Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8999903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:14:31+00:00 2026-06-16T00:14:31+00:00

I use AFNetworking for network operations So which is the right way to send

  • 0

I use AFNetworking for network operations

So which is the right way to send request to the https://api.box.com/2.0/files/content?
Right now I receive HTTP//1.1 500 Internal Server Error

Code

NSMutableData *body = [NSMutableData data];
NSString *boundaryString = [NSString stringWithFormat:@"rn-------------------------%.0frn", [[NSDate date] timeIntervalSince1970]];
NSData *boundary = [boundaryString dataUsingEncoding:NSUTF8StringEncoding];

NSURL *url = [NSURL URLWithString:kBoxNetFileUploadURLFormat];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[BoxNet attachAuthHeaderForRequest:request];

[request addValue:[BoxNet SHA1:content] forHTTPHeaderField:@"Content-MD5"];
[request addValue:[NSString stringWithFormat:@"multipart/form-data; boundary=\"%@\"", boundaryString] forHTTPHeaderField:@"Content-Type"];


[body appendData:boundary];

[body appendData:[@"Content-Disposition: form-data; name=\folder_id\"" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[folderID dataUsingEncoding:NSUTF8StringEncoding]];

[body appendData:boundary];

[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; filename=\"%@\"; name=\"filename\"", filename] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: application/octet-stream" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:content];

[body appendData:boundary];

[request setHTTPBody:body];
[request setValue:[NSString stringWithFormat:@"%d", body.length] forHTTPHeaderField:@"Content-Length"];


AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
    completion(JSON, nil);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *err, id JSON) {
    completion(JSON, err);
}];

[operation start];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:14:32+00:00Added an answer on June 16, 2026 at 12:14 am

    The problem was Wrong boundary & parameters formatting, request handling is the same.

    Attaching the new code:

    NSMutableData *body = [NSMutableData data];
    NSString *boundary = [NSString stringWithFormat:@"%.0f", [[NSDate date] timeIntervalSince1970]];
    
    NSURL *url = [NSURL URLWithString:@"https://api.box.com/2.0/files/content"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"POST"];
    [BoxNet attachAuthHeaderForRequest:request];
    
    [request addValue:[BoxNet SHA1:content] forHTTPHeaderField:@"Content-MD5"];
    [request addValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary] forHTTPHeaderField:@"Content-Type"];
    
    // add file body and filename
    [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition:form-data;filename=\"%@\";name=\"filename\"\r\n", filename] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"Content-Type:application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:content];
    
    // folder id
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"Content-Disposition:form-data;name=\"folder_id\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[folderID dataUsingEncoding:NSASCIIStringEncoding]];
    
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    
    [request setHTTPBody:body];
    

    I’ve solved my problem thanks to this article: Objective-C Box 2.0 File Upload – Problems

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Use a Content Delivery Network (CDN) Compress components with gzip Configure entity tags (ETags)
I am attempting to use AFNetworking with an XML-RPC based API while using GDataXML
I use AFNetworking in my app for every request (like login, get data from
Use Case Show a photo uploaded by the user in a square box with
I'm using AFNetworking to make a web request. After the web request completes. I
Use the static modifier to declare a static member, which belongs to the type
Use Case I need to package up our kml which is in a String
Why should one use AFNetworking's async methods, when an async call can be done
I am making use of AFNetworking library for the first time and i have
Is it possible to use Basic and OAuth authorization headers in the same request

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.