Http.post not receiving data in php


#1

Why I am not receiving data in php


let body     : string   = "key=insert&name=" + this.name + "&email=" + this.email + "&contact=" + this.number,
         type: 'application/x-www-form-urlencoded',
          headers  : any      = new Headers({ 'Content-Type': type}),
          options  : any      = new RequestOptions({ headers: headers }),
          url      : any      = "http://192.168.2.31/fetch/public/api/user/register";
         
        this.http.post(url,{body},{headers})
        .subscribe((data) => {
          console.log(JSON.stringify(data));        
        })

in php

print_r($_SERVER);
print_r($_REQUEST[‘name’]);

error -> undefined $_REQUEST[‘name’]


#2

I am not very familiar with the HTTP module yet, but I see that you are declaring the body as a string, is this the proper way to do it? As you are getting an error about the name variable, I guess the body ain’t getting created properly for some reason. May be you can make the body an object and then while calling the post method JSON.stringify() it?


#3

Done that way also still same


#4

Hm okay, would like to see that code. This might help too:

http://www.nikola-breznjak.com/blog/javascript/ionic2/posting-data-from-ionic-2-app/


#5

You are using multiple variable declaration syntax, I am not sure if that’s allowed in typescript. It might be causing the problems? You should probably try to either create a single object and use it’s properties wherever needed or create each of the variables individually.


#6

Thank you for posting for the same problem multiple times in different stages, I wasted my time responding to your other topics.

Does your code actually call the URL successfully?


#7

Hahaha
Yes it’s calling but the problem is there when I am accessing the key it’s showing invalid key name and if check in headers body is going in json format