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

  • Home
  • SEARCH
  • 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 605297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:07:49+00:00 2026-05-13T17:07:49+00:00

How to create Http Post data to the web server ? Do you have

  • 0

How to create Http Post data to the web server ?

Do you have an example related this issue ?

Thanks in advance.

  • 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-05-13T17:07:49+00:00Added an answer on May 13, 2026 at 5:07 pm

    It depends on what you want to send to the server. for instance: Image file or just Text(like that from a http form).

    For an image file that is in the format UIIMage:

    NSData *imageData = [NSData dataWithContentsOfFile:ImagePath];
    

    or

    NSData *imageData = UIImageJPEGRepresentation(myImage.image, 1.0);
    

    Set your remote url(for instance if you are using php)

    NSString *urlString = "http://yourdomain.com/yourphpfile.php" 
    

    The rest of the code:

    NSMutableURLRequest *request2 = [[[NSMutableURLRequest alloc] init] autorelease];
                [request2 setURL:[NSURL URLWithString:urlString]];
                [request2 setHTTPMethod:@"POST"];
    
                NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
                NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
                [request2 addValue:contentType forHTTPHeaderField: @"Content-Type"];
    
    
    NSMutableData *body = [NSMutableData data];
    
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];    
    
    [body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name='userfile'; filename='"] dataUsingEncoding:NSUTF8StringEncoding]];
    //give any name for your file(this case image file example)         
    [body appendData:[[NSString stringWithString:pic_filename.jpg] dataUsingEncoding:NSUTF8StringEncoding]];
    
    [body appendData:[[NSString stringWithString:@"'\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    
    [body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    
    
    //add the file data to the http body            
        [body appendData:[NSData dataWithData:imageData]];
    
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    
    // setting the body of the post to the reqeust
    [request2 setHTTPBody:body];
    

    The case of Just Text(Similar to the $_GET in php)

    Prepare the data you want to send. For the first name from a form for instance

    //You have your first name stored in the_first_name_to_send variable
    
    NSString *f_name = nil;
    f_name = [[NSString alloc] initWithFormat:@"%@", the_first_name_to_send];
    
    //Encoding conversion
    //This is optional but it ensures that every character encoding type is sent without issues
    NSString* escapedUrlStringFirstName =[f_name stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
    
    NSString *string1 = @"firstName=";
    
    NSString *myRequestString;
            myRequestString = [string1 stringByAppendingString:escapedUrlStringFirstName];
    NSData *myRequestData = [ NSData dataWithBytes: [ myRequestString UTF8String ] length: [ myRequestString length ] ];
    
    NSMutableURLRequest *request2 = [[[NSMutableURLRequest alloc] init] autorelease];
    
    [request2 setHTTPBody: myRequestData ];
    
    [request2 setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
    
    NSData *returnData2 = [ NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil ];
    
    returnData2 = nil;
    

    Uploading image file (the server side yourphpfile.php)

    $file_tmp = $_FILES['userfile']['tmp_name'];
    $filename = $_FILES['userfile']['name'];
    

    Sending text using http post (the server side yourphpfile.php)

    $fname = $_POST["firstName"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 376k
  • Answers 376k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should go for the separate function in a different… May 14, 2026 at 8:43 pm
  • Editorial Team
    Editorial Team added an answer If your site is slow, you need to figure out… May 14, 2026 at 8:43 pm
  • Editorial Team
    Editorial Team added an answer private void listView1_SelectedIndexChanged(object sender,EventArgs e) { ListView.SelectedListViewItemCollection album = this.listView1.SelectedItems;… May 14, 2026 at 8:43 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.