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 8087319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:44:16+00:00 2026-06-05T18:44:16+00:00

I am using NSURLConnection to send same data ( NSString ) to the server

  • 0

I am using NSURLConnection to send same data (NSString) to the server and i would like to add with them an image or a file so what’s the value of the content type?

Encoding

- (NSData *)encodingData:(NSMutableDictionary *)dictionary
{
    NSMutableArray *arrayPosts = [[NSMutableArray alloc] init];
    [dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
         NSString *encodedKey = [key stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
         NSString *encodedValue = [obj stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [arrayPosts addObject:[NSString stringWithFormat:@"%@=%@",encodedKey,encodedValue]];
    }];
    NSString *encodedArrayPosts = [arrayPosts componentsJoinedByString:@"&"];
    return [encodedArrayPosts dataUsingEncoding:NSUTF8StringEncoding];
}

Send Data

- (void)startAsyncRequest
{
   // Enable the network activity indicator in the status bar
   [self enableActivityIndicatorInStatusBar];

   // Setting of the request
   NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL:self.url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];
   [urlRequest setHTTPMethod:self.method];
   [urlRequest setHTTPBody:[self encodingData:self.dictionaryPosts]];

   // Send the request
   NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];

   if (connection) {
      // Connection succeded 
     self.receiveData = [NSMutableData data];
   } else {
      // Connection Failed
      self.error = @"Connection Failed";
      // Inform the user that the connection failed
      [self.delegate requestFailed:self];
   }
}
  • 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-05T18:44:19+00:00Added an answer on June 5, 2026 at 6:44 pm

    You need to pass the data into as stream type in your server

    public InsertImage(Stream stream)
    

    Something like that then parse the stream type.

    This is how to build your request using some boundaries

    - (NSURLRequest *)buildRequest:(NSData *)paramData fileName:(NSString *)name {
        NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
        NSString *charset = (NSString *)CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));
        [request setURL:self.url];
        [request setHTTPMethod:self.method];
    
        NSString *boundary = @"0xKhTmLbOuNdArY";
        NSString *endBoundary = [NSString stringWithFormat:@"\r\n--%@\r\n", boundary];
    
        NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; charset=%@; boundary=%@", charset, boundary];
        [request addValue:contentType forHTTPHeaderField: @"Content-Type"];
    
        NSMutableData *tempPostData = [NSMutableData data]; 
        [tempPostData appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    
        // Sample Key Value for data
        [tempPostData appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", @"Key_Param"] dataUsingEncoding:NSUTF8StringEncoding]];
        [tempPostData appendData:@"Value_Param"] dataUsingEncoding:NSUTF8StringEncoding]];
        [tempPostData appendData:[endBoundary dataUsingEncoding:NSUTF8StringEncoding]];
    
        // Sample file to send as data
        [tempPostData appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@\"\r\n", name] dataUsingEncoding:NSUTF8StringEncoding]];
        [tempPostData appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
        [tempPostData appendData:paramData];
        [tempPostData appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
        [request setHTTPBody:tempPostData];
        return request;
    }
    

    You should get the stream type data on your server side and parse it, you can get the value base on the Key you pass e.g. Key_Param, and the name(fileName)of the file you send.

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

Sidebar

Related Questions

I am using NSURLConnection to send request to server and receive response like this
I want to send a large amount of data to a server using NSURLConnection
I want to send image data to the server, For that, I have appended
i am using NSURLConnection to download file from server and storing it locally as
iam currently using NSURLConnection class to hit my server and get some data from
I have an application that upload file to server using NSUrlConnection. It was placed
I'm using NSURLConnection to pull data from a webpage. I'm looking to find a
I'm using NSURLConnection to grab an XML file. I parse the XML file and
I'm using NSURLConnection with sendAsynchronousRequest method (and handing the data in block). Using above
I'm getting an image over HTTP, using NSURLConnection, as follows - NSMutableData *receivedData; -

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.