http request post-ionic method 2, angular 2

1

I am making a post http request, but without success ...

Actually I have a success in the header the same returns, however the body is not rolling.

My code looks like this:

          postRequest() {
          let myHeader = new Headers({

        "Content-Type" : "application/x-www-form-urlencoded",


       });
        let options = new RequestOptions({
          headers: myHeader

        });
        let body = JSON.stringify({

          key: "versao" , value:"1.1"


        });

In the body I need a request Body with the key and value to return the query done in webservice.

I have seen in some sites that say that the body has to be written in the format "application / x-www-form-urlencoded".

could help?

    
asked by anonymous 23.11.2017 / 19:06

1 answer

0

Ronald. You are doing a POST but are not sending any data to the server. Just below, you say you want to do a web-service query, right? For this, the correct method is the GET. It would look something like this:

getRequest(): Observable<Response>{
        let myUrl = "http://www.google.com"; //sua url de acesso
        let myHeader = new Headers({'Content-Type': 'application/json'}); // JSON!
        let options = new RequestOptions({headers: myHeader});
        let body = JSON.stringify({
          key: "versao" , value:"1.1"
        });

      return this.http.get(myUrl, body).map(this.handleData);
       // chama a função abaixo
}

private handleData(res: Response) {
  let body = res.text();
  if (body) {
    return body.data;
  } else {
    return {};
  }
}
    
28.11.2017 / 13:53