Using POST Restful api return result 200


#1

Hi, I am using POST to call api with a java server and following the below link to update the web.xml in backend server to solve CORD problem:


but when I call the api again, it is not return a json result i wanted. It return :

Response {_body: “”, status: 200, ok: true, statusText: “OK”, headers: Headers, …} .

Did anyone know how to deal with it? Thanks a lot =)


Ionic call RESTful api with a param base64 string
#2

you didn’t want a status 200?


#3

Hi, FnnHuman, thanks for your reply. Because I have data returned by server in this api, i want those data rather than status 200.


#4

but status 200 means that everything is good and if there was any data returned from server you should have access to it now

this.http.post('something/api/', JSON.stringify(details), { headers: headers })
        .map(res => res.json())
        .subscribe(data => {
          console.log(data); //you have access to data
        }, (err) => {
          console.log(err); //oops error
        });

#5

How are you calling that address?
What code is outputting that Reponse object you posted?
Did you look at the request in your browser’s dev tools network tab? Does it return the data?


#6

I call it this way:

    this.http.post(apiUrl+'register', JSON.stringify(body), {headers: headers})
    .map(res => res.text() ? res.json() : res)
    .subscribe((data) => {
      console.log("NULRA CHECKING : ", data);      
    },(err) => {
      reject(err);
    });

But the data i printed is status 200… not the data that I needed


#7

Why this? See the example @FnnHuman posted.


#8

I have try @FnnHuman example, it will go to error directly.