Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant't get post data when request a service by POST method #3

Open
lijiebin opened this issue Jul 17, 2017 · 1 comment
Open

Cant't get post data when request a service by POST method #3

lijiebin opened this issue Jul 17, 2017 · 1 comment

Comments

@lijiebin
Copy link
Contributor

Because the data of setBody not in $_POST but in php://input

 private function simpleRequest(Request $request, RestClient $client)
    {
        if ($request->getRoute()->isAggregate()) throw new NotImplementedException('Aggregate ' . strtoupper($request->method()) . 's are not implemented yet');

        $client->setBody($request->getContent());

        if (count($request->allFiles()) !== 0) {
            $client->setFiles($request->allFiles());
        }

        $parametersJar = array_merge($request->getRouteParams(), ['query_string' => $request->getQueryString()]);
        $response = $client->syncRequest($this->actions->first()->first(), $parametersJar);

        return $this->presenter->format((string)$response->getBody(), $response->getStatusCode());
    }
@sidigi
Copy link

sidigi commented Dec 18, 2019

Add to RestClient

    /**
     * @param string $form params
     *
     * @return $this
     */
    public function setFormParams($params)
    {
        unset($this->guzzleParams['headers']['Accept'], $this->guzzleParams['headers']['Content-Type']);

        $this->guzzleParams['form_params'] = $params;

        return $this;
    }

Add to GatewayController

    private function simpleRequest(Request $request, RestClient $client)
    {
        //...
        if ($request->isMethod('post')) {
            $client->setFormParams($request->post());
        } else {
            $client->setBody($request->getContent());
        }
        //...
    }

Not the best solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants