0

problem

i tried with $request->request->all() //var_dump output:array(0){}

symfony code

public function registerAction(Request $request) {

   var_dump($request->request->all());die;
  }

Angular2 service

export class UserRegistrationService {

 constructor(private http: Http) { }

 private headers = new Headers({'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'});
 private insertdataUrl = 
'http://localhost/abc/web/app_dev.php/api/v1/register-user';


 /* create new user */
create(name: string): Promise<UserDetails> {

    return this.http
    .post(this.insertdataUrl, JSON.stringify({name: name}), {headers: this.headers})
    .toPromise()
    .then(res => res.json().data as UserDetails)
    .catch(this.handleError);
}

FormData

{"name{"email":"[email protected]","username":"abc","password":"","repeatpassword":""}}:

solution that works

$data = json_decode(file_get_contents('php://input'), true);

// able to get paramters //get,or //post

can anyone suggest why request doesn't print some values.

  • here im posting form from angular2.
1
  • Serialize you data rather than json encoding it Commented Sep 4, 2017 at 8:12

2 Answers 2

1

Symfony uses different containers for Post and Get. Try this way.

# Post
$request->request->all()

# Get
$request->query->all() 
Sign up to request clarification or add additional context in comments.

2 Comments

"Chrome DevTools -> Network -> Request Payload" what you see in the field. Looks like the problem is not in the symfony.
data is posted ok:{"name{"email":"[email protected]","username":"abc","password":"","repeatpassword":""}}:
0

solution that worked for me

i changed headers

from

  private headers = new Headers({'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'});

To

 private headers=new Headers({ 'Content-Type': 'application/json' });
  • now im able to recieve data.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.