A
A
Abra Kadabra2018-05-27 17:53:43
PHP
Abra Kadabra, 2018-05-27 17:53:43

How to correctly set body in POST request, angular 6?

Of course, I understand that it's done like this:
http.post(url, body);
body is an object with key:value pairs.
Here it is not clear to me how it comes to the server. How is the object? In this case, you can't just take and make $_POST['email'] on the server, right? The object comes. How can I form a request that will be convenient $_POST "it? After all, if I use a non-angular form. The request comes like this: In this case, everything works.
{email: '[email protected]', password: 'pw'}
username=mail%mail.com&password=pw

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Abra Kadabra, 2018-06-22
@Jmaster

If anyone needs it, this header helped:

private options = {
        headers: new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded' })
};
...
this.http.post( url, body, options);

T
tonx92, 2018-06-21
@tonx92

Leave it in Angular:
On the server, you can process it like this:

$postData = file_get_contents('php://input');
$postData = json_decode($postData, true);
// Обращаться так
//$postData['email']
//$postData['password']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question