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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:35:08+00:00 2026-06-12T03:35:08+00:00

I have been searching all over stackoverflow and Google for a solution to my

  • 0

I have been searching all over stackoverflow and Google for a solution to my problem.

I have created two projects with Zend Framework – Project1 and Project2 – and I want to implement web services on one of them. The idea is to send a JSON-string to Project1 and receive back a JSON with all the details associated with that variable using POST. Now I have created a TestController on Project2:

public function indexAction(){

    $uri = 'http://project1.com/WebService/data';

    $config = array(
        'adapter'   => 'Zend_Http_Client_Adapter_Curl',
        'curloptions' => array(CURLOPT_FOLLOWLOCATION => true),
    );
    $client = new Zend_Http_Client($uri, $config);

    $request = $client->request('POST');

    print_r($request->getBody());

    exit();

}

The above code works. It reads the dataAction from the Project1 controller and gives me an output of whatever is echoed. But when I try this:

public function indexAction(){

    $uri = 'http://project1.com/WebService/data';

    $config = array(
        'adapter'   => 'Zend_Http_Client_Adapter_Curl',
        'curloptions' => array(CURLOPT_FOLLOWLOCATION => true),
    );
    $client = new Zend_Http_Client($uri, $config);

    $data = array(
            'userID'      => 'TEST TEST',
            'value'       => 1,
            'description' => 'ABCDEFG',
    );

    $request = $client->request('POST');

            $json = json_encode($data);

            $client->setRawData($json, 'application/json')->request('POST');

    exit();

}

And on the server side when I try displaying inside dataAction:

public function dataAction(){

    var_dump($this->getRequest()->getParam('var-name'));

    var_dump($_POST);

    die();      

}

I get an output of this: NULL array(0) { } …. I get the same output when I try it on the client side. Also to mention.. I also tried opening the php://input file but got an empty string…

What am I missing??? I have frustrated myself searching on it since morning but got no solution.

Thanks in advance for response.

  • 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-12T03:35:10+00:00Added an answer on June 12, 2026 at 3:35 am

    Here is what you are missing:

    $json = json_encode($data);
    $client->setRawData($json, 'application/json')->request('POST');
    

    sends a POST request but the data in the POST body is not a url-encoded string, instead it is just raw JSON.

    Calling $this->getRequest()->getParam('foo') looks at the PHP superglobals $_GET and $_POST which will not contain any of the JSON parameters. The reason it will be empty is because PHP couldn’t parse the POST data since it was JSON and not HTTP url-encoded content.

    The solution is to use something like this in the dataAction if you want to receive JSON data in the POST body.

    $post = $this->getRequest()->getRawBody();
    
    try {
        $json = Zend_Json::decode($post);
    
        // now access parameters from $json array
    } catch (Zend_Json_Exception $ex) {
        echo "Failed to decode request, POST did not contain valid JSON.";
    }
    

    Edit: Here is the full code you can mess with.

    public function requestAction()
    {
        // CHANGE THIS
        $uri = 'http://playground/zendapp/public/index/data';
    
        $config = array(
                'adapter'   => 'Zend_Http_Client_Adapter_Curl',
                'curloptions' => array(CURLOPT_FOLLOWLOCATION => true),
        );
        $client = new Zend_Http_Client($uri, $config);
    
        $data = array(
                'userID'      => 'TEST TEST',
                'value'       => 1,
                'description' => 'ABCDEFG',
        );
    
        $json = json_encode($data);
    
        $resp = $client->setRawData($json, 'application/json')->request('POST');
    
        var_dump($resp->getBody());
    
        exit();
    
    }
    
    public function dataAction()
    {
        $post = $this->getRequest()->getRawBody();
    
        try {
            $json = Zend_Json::decode($post);
    
            print_r($json);
        } catch (Exception $ex) {
            echo "failed to decode json";
        }
    
        exit;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been searching all over stackoverflow and google to find a reason as
I've been searching all over google and have found no solution, which is unbelievable!
Hey, I have been searching all over for a solution to injecting into action
I have been searching the web and all over stackoverflow, but yet couldn't find
I have been searching all over and i cant seem to find a solution.
I have been searching all over the internet for a solution, but could not
I have been extensively searching all over the net last night until today and
I have been searching all over the Internet, but did not find that exact
I have been searching all over the internet for an answer to this. It
I have been searching all over but I can't find any answer to this.

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.