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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:20:06+00:00 2026-05-23T06:20:06+00:00

i took this code from a different question and my script file has more

  • 0

i took this code from a different question and my script file has more inputs, not just mydata, also the data going into the mydata should not be static text, it should be from a NSString.

So my question is, how do i post multiple pieces of data to my script and how would I input a value from a NSString because my understand is i cannot use NSStrings with c data types. not sure if thats the correct terminology so please correct me if i am wrong.

const char *bytes = "mydata=Hello%20World";

NSURL *url = [NSURL URLWithString:@"http://www.mywebsite.com/script.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

[request setHTTPMethod:@"POST"];
[request setHTTPBody:[NSData dataWithBytes:bytes length:strlen(bytes)]];

NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
//NSString *responseString = [[NSString alloc] initWithFormat:@"%@", responseData];
NSLog(@"responseData: %@", responseData);

userData = responseData;

New issue using answer below

NSMutableData *data = [NSMutableData data]; 

NSString *number = numberIB.text;
NSString *name = nameIB.text;

NSString *nameString = [[NSString alloc] initWithFormat:@"name=", name];
NSString *numberString = [[NSString alloc] initWithFormat:@"number=", number];

NSLog(nameString);
NSLog(numberString);

[data appendData:[nameString dataUsingEncoding:NSUTF8StringEncoding]];
[data appendData:[numberString dataUsingEncoding:NSUTF8StringEncoding]];

NSURL *url = [NSURL URLWithString:@"http://www.siteaddress.com/test.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

[request setHTTPMethod:@"POST"];
//[request setHTTPBody:[NSData dataWithBytes:data length:strlen(data)]];
[request setHTTPBody:data];

NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
//NSString *responseString = [[NSString alloc] initWithFormat:@"%@", responseData];
NSLog(@"responseData: %@", responseData);

the NSLogs for nameString and numberString come back name= and number= without any data. causing no data to be sent to my script.

  • 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-23T06:20:07+00:00Added an answer on May 23, 2026 at 6:20 am

    You can use an NSMutableData object to append bytes as needed, like so:

    NSMutableData *data = [NSMutableData data]; 
    const char *bytes = "mydata=Hello%20World";
    [data appendBytes:bytes length:strlen(bytes)];
    
    //...
    
    const char *moreBytes = "&someMoreData=Fantastic";
    
    [data appendBytes:moreBytes length:strlen(moreBytes)];
    

    Edit: If you want to append a NSString into the data buffer, you can use -[NSString dataUsingEncoding:] and pass it off to -appendData:

    NSString *someString = @"blah";
    [data appendData:[someString dataUsingEncoding:NSUTF8StringEncoding]];
    
    [request setHTTPBody:data];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question has been asked before, and I took a look at
Okay first of all, I admit I took elements from this question here: How
I found this statement is some old code and it took me a second
I took the plunge this afternoon and began studying LINQ, so far just mucking
I called this function once per frame and it took my FPS from >400
Looking at the related questions, I don't think this specific question has been asked,
It took me FOREVER to finally find code that can download a doc file
I'm using code examples from this article by Rick Strahl: http://www.west-wind.com/weblog/posts/324917.aspx to make async
Before reading the question: This question is not about how useful it is to
This took me a while to figure out and I found the answer on

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.