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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:09:15+00:00 2026-06-02T05:09:15+00:00

I am trying to POST data to a JSON webservice. I can succeed if

  • 0

I am trying to POST data to a JSON webservice. I can succeed if I do this:

curl -d "project[name]=hi&project[description]=yes" http://mypath.com/projects.json

I’m trying to use code like this to accomplish it:

 NSError *error = nil;
 NSDictionary *newProject = [NSDictionary dictionaryWithObjectsAndKeys:self.nameField.text, @"name", self.descField.text, @"description", nil];
 NSLog(@"%@", self.descField.text);
 NSData *newData = [NSJSONSerialization dataWithJSONObject:newProject options:kNilOptions error:&error];
 NSMutableURLRequest *url = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://mypath.com/projects.json"]];
 [url setHTTPBody:newData];
 [url setHTTPMethod:@"POST"];
 NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:url delegate:self];

My request creates a new entry, but that entry is blank in both the name and description. My NSLog in the above code produces the appropriate output.

  • 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-02T05:09:16+00:00Added an answer on June 2, 2026 at 5:09 am

    You are mixing up two things here. The webservice returns a JSON result http://mypath.com/projects.json but in your curl example, your HTTP body is a plain old querystring form body. Here’s what you need to do to make this work:

    NSError *error = nil;
    NSString * newProject = [NSString stringWithFormat:@"project[name]=%@&project[description]=%@", self.nameField.text, self.descField.text];
    NSData *newData = [newProject dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]; // read docs on dataUsingEncoding to make sure you want to allow lossy conversion
    NSMutableURLRequest *url = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://mypath.com/projects.json"]];
    [url setHTTPBody:newData];
    [url setHTTPMethod:@"POST"];
    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:url delegate:self];
    

    This will be equivalent to the curl call you made above. Alternatively, if you wanted to post JSON (as your ObjC code example was doing) using curl, you would do it like so:

    curl -d '"{\"project\":{\"name\":\"hi\",\"project\":\"yes\"}}"' -H "Content-Type: application/json" http://mypath.com/projects.json

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

Sidebar

Related Questions

I am trying to send data, in json format to my webservice, using POST.
When I post my ajax data to my webservice I keep getting this error.
I noticed when trying to post form data in JSON format, that the following
I'm writing a rest service which accepts json documents with http post. I can
I am trying to post data from PHP to Server which is built in
I'm trying to POST data from an iOS app to Node.js/Express. I cannot get
I'm trying to read POST data in a PHP script. My first instincts led
I am trying to post some data with jQuery Ajax, but the parameters in
I'm trying to send post data between pages with Post. Not a form -
I'm trying to post a JavaScript data object with the following: $.post(frm.attr(action), data, function(res)

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.