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

The Archive Base Latest Questions

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

I have the following script in PHP: <?php $sender = $_POST[‘sender’]; $rcpt = $_POST[‘rcpt’];

  • 0

I have the following script in PHP:

<?php $sender = $_POST['sender'];
      $rcpt = $_POST['rcpt'];
      $message = $_POST['message'];

      $someArray = array("Bannana", "Apple", "SomeCheese");
      print_r($someArray);

      echo json_encode($someArray);

?>

and the following button action:

NSString *myRequestString = @"sender=my%20sender&rcpt=my%20rcpt&message=hello";
NSData *myRequestData = [ NSData dataWithBytes: [ myRequestString UTF8String ] length: [ myRequestString length ] ];
NSMutableURLRequest *request = [ [ NSMutableURLRequest alloc ] initWithURL: [ NSURL URLWithString: @"http://development.com/ios/responseScript.php" ] ];

/**********Set Request properties*************/
[ request setHTTPMethod: @"POST" ];
[ request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
[ request setHTTPBody: myRequestData ];


NSURLResponse *response;
NSError *err;

NSDictionary *returnedDictionary = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSUInteger content = [NSString stringWithUTF8String:[returnedDictionary count]];
//NSLog(@"responseData: %@", content);
self.responseLabel.text = [NSString stringWithFormat:@"Count:    %u", content];

What I am trying to achieve is that the json being echoed should come back in the form of a response and be printed to the screen. At best I got that the return was null and am sure it is not. I have a working example but using array instead of dictionary, and the outcome is attached below:

NSString *myRequestString = @"sender=my%20sender&rcpt=my%20rcpt&message=hello";
NSData *myRequestData = [ NSData dataWithBytes: [ myRequestString UTF8String ] length: [ myRequestString length ] ];
NSMutableURLRequest *request = [ [ NSMutableURLRequest alloc ] initWithURL: [ NSURL URLWithString: @"http://development.com/ios/responseScript.php" ] ];
[ request setHTTPMethod: @"POST" ];
[ request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
[ request setHTTPBody: myRequestData ];
NSURLResponse *response;
NSError *err;
NSData *returnData = [ NSURLConnection sendSynchronousRequest: request returningResponse:&response error:&err];
NSString *content = [NSString stringWithUTF8String:[returnData bytes]];
//NSLog(@"responseData: %@", content);
self.responseLabel.text = [NSString stringWithFormat:@"Data:    %@", content];

Outcome:

2013-01-30 19:07:07.919 testResponse[15921:c07] responseData: Array (
[0] => Bannana
[1] => Apple
[2] => SomeCheese ) [“Bannana”,”Apple”,”SomeCheese”]

Please help? Thank you a lot

  • 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-18T00:13:15+00:00Added an answer on June 18, 2026 at 12:13 am
    NSDictionary *returnedDictionary = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
    

    You are getting an NSData object here, not an NSDictionary object.

    NSUInteger content = [NSString stringWithUTF8String:[returnedDictionary count]];
    

    You are getting the number of items in the (nonexistent) dictionary here, not its contents.

    Given that you are updating user interface elements in this code, I am assuming it’s being run on the main thread. You shouldn’t be making synchronous requests on the main thread, that will just make your application hang while it’s waiting on the network. Either make synchronous requests on a background thread or make asynchronous requests on the main thread.

    From there, look at the documentation for the classes you are using and pay attention to the warnings Xcode is surely giving you.

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

Sidebar

Related Questions

I have the following code validation php script: if(empty($_POST['captcha_code'])) { $error = 1; $code[3]
Hello I have the following script in PHP: $correct = array(a, a, a, a);
I have the following script myclass.php <?php $myarray = array('firstval','secondval'); class littleclass { private
I have the following script validation.php <?php if(!isset($_SESSION['userId'])){ session_destroy(); header('Location: home.php'); exit; } ?>
I have the following PHP script: <?php $vote_type = $_GET['type']; $book = $_GET['book']; $id
I have the following PHP script with the working (according to JsonViewer ) JSON
I have the following PHP script: <?php $fortune = `fortune`; echo $fortune; ?> but
I have the following function in a PHP script, which returns and API call:
I have the following jqGrid script: jQuery(#editgrid).jqGrid({ url: editing.php?q=1, datatype: xml, // ... Where
i have the following simple script <input class=input type=text name=password style=color: #797272; value= <?php

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.