Please open below link and help me

It means extra < coming in your api response
Possible solutions according to me

1.Copy response in string and remove extra < and then copy it to original form and then do parsing
Or
2.Tell your backend/api developers to remove it from response or db.

but in response in postman it shows correct json then why its not coming in app

Yes gone through your link.
I think in response format of your server it mentioned xml as response type can you please confirm.

Also for headers try to use this

import { HttpHeaders } from '@angular/common/http';
const httpOptions = {
      headers: new HttpHeaders({
        'Content-type': 'application/json',
      })
    };

still not working it gives response in html code and in server side he also mentioned type as application/json

When you are requesting login api try to check response.

1.If you are testing on Android Device/Emulator
do it in Google Crome by inspect
1.what is response type?
2.what is response:?

2 .if you are testing it on ios Simulator/Device
try to check on Safari browser in develop option so that you can get details.

If possible try to paste your response which you are getting on login api.

Try to use https://codebeautify.org/ to check whether response in correctly formated or not.

when i print response in console using console.log(“json data”,res) it gives

json data
Response {_body: “↔↔ ↔ <meta charset=
ype=“text/javascript”>↔ ↔”, status: 200, ok: true, statusText: “OK”, headers: Headers, 
}
headers: Headers
_headers: Map(4) {“pragma” => Array(1), “content-type” => Array(1), “cache-control” => Array(1), “expires” => Array(1)}
_normalizedNames: Map(4) {“pragma” => “pragma”, “content-type” => “content-type”, “cache-control” => “cache-control”, “expires” => “expires”}
proto: Object
ok: true
status: 200
statusText: “OK”
type: 2

_body: “↔↔ ↔ ↔ Quality Control | Admin System Log in↔ ↔ ↔ ↔ ↔↔ ↔ ↔ ↔ ↔ ↔

↔ ↔
↔

Sign In

↔
↔
↔
The Email field is required. ×
↔
The Password field is required. ×
↔
↔
↔ ↔ <form ↔
↔ ↔ ↔
↔
↔ ↔ ↔
↔
↔
↔ ↔
↔
↔ ↔
↔
↔ ↔↔ <”>Forgot Password
↔ ↔
↔
↔↔ ↔ ↔ ↔"
proto: Body

From your response It looks like its not proper JSON response format.

To print response in JSON write like this
console.log(“json data”, JSON.stringify(res))

It will print JSON format of your response.

Please paste your code on https://codebeautify.org/ and check whether JSON is valid or not
and paste that json here.

You are testing app on iOS device/Simultor or Android device/Emulator ?
Note:While pasting code on forum try not to reveal urls

when i use console.log(“json data”, JSON.stringify(res)) this it prints html code in json format
and i’m testing app on android device and google chrome

json comes like this:

{"_body":"\n\n \n <meta charset=“UTF-8”>\n Quality Control | Admin System Log in\n \n <link href=“http://146.66.92.93/~advent37/QualityControl/assets/bootstrap/css/bootstrap.min.css” rel=“stylesheet” type=“text/css” />\n <link href=“https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css” rel=“stylesheet” type=“text/css” />\n <link href=“http://146.66.92.93/~advent37/QualityControl/assets/dist/css/AdminLTE.min.css” rel=“stylesheet” type=“text/css” />\n\n \n \n \n \n <body class=“login-page”>\n <div class=“login-box”>\n <div class=“login-logo”>\n <a href="#">\n\t\t<img src=“http://146.66.92.93/~advent37/QualityControl/assets/images/logo_new.png” class=“user-image” alt=“User Image”/>\n\t\t
Admin System\n \n <div class=“login-box-body”>\n <p class=“login-box-msg”>Sign In

\n <div class=“row”>\n <div class=“col-md-12”>\n <div class=“alert alert-danger alert-dismissable”>The Email field is required. <button type=“button” class=“close” data-dismiss=“alert” aria-hidden=“true”>×\n<div class=“alert alert-danger alert-dismissable”>The Password field is required. <button type=“button” class=“close” data-dismiss=“alert” aria-hidden=“true”>×\n \n \n \n \n <div class=“form-group has-feedback”>\n <input type=“email” class=“form-control” placeholder=“Email” name=“email” required />\n <span class=“glyphicon glyphicon-envelope form-control-feedback”>\n \n <div class=“form-group has-feedback”>\n <input type=“password” class=“form-control” placeholder=“Password” name=“password” required />\n <span class=“glyphicon glyphicon-lock form-control-feedback”>\n \n <div class=“row”>\n <div class=“col-xs-8”> \n \n \n <div class=“col-xs-4”>\n <input type=“submit” class=“btn btn-primary btn-block btn-flat” value=“Sign In” />\n \n \n \n\n
\n \n \n \n\n \n",“status”:200,“ok”:true,“statusText”:“OK”,“headers”:{“pragma”:[“no-cache”],“content-type”:[“application/json; charset=UTF-8”],“cache-control”:[“no-store”," no-cache"," must-revalidate"],“expires”:[“Thu”," 19 Nov 1981 08:52:00 GMT"]},“type”:2}

Yes thats what I want.
Its problem from your sever side response

1.Why html is coming in response? Is that architecture of your app/project that HTML will come in response and then you will render it on screen?

2.If answer of above question is NO . Then tell your backend team to give proper JSON format response

Its like response in JSON but internally HTML putted in in objects.

So final solution can be response should be proper JSON.

See at the time postman can be showing response correctly but in coding its not that much easy to parse this type of response.

Hi
Have you resolved that?
If so please let me know how.

Thanks

Not yet still i’m facing same issue and backend developer says all is correct from his side

and when i use static json like below

this.resposeData = {
“email”: "admin@example.com",
“password”: “admin”,
“status”: 1
}
console.log(“data”, this.resposeData);
console.log(“userdata”, this.resposeData.userData );
if (this.resposeData.userData ) {
localStorage.setItem(‘userData’, JSON.stringify(this.resposeData ))
this.navCtrl.push(HomePage);
}
else {
this.presentToast(“Please enter valid username and password”);
}

then console.log(“userdata”, this.resposeData.userData ); it prints undefined

The server may be doing a redirect

The content of the html suggests some sort of login page

Go to the link with ur browser and login

If it then provides Json data, u know u have an authentication step to complete prior to fetching data (in header etc)

console.log(“userdata”, this.resposeData.userData ); it prints undefined
if userData is not in resposeData then it will not print.

actually, the problem is that i’m sending parameters in json format and in server side it takes response in form data type
and thanks for your help

1 Like