I am using angular 8
- I am using HttpParams in Sending Data to the Server via Post method
- I am getting 502 status code error, sending data via HttpPrams
ERROR
HttpErrorResponse {headers: HttpHeaders, status: 502, statusText: "Bad Gateway", url: "http://central-portal-app-alb-1565375077.ap-south-1.elb.amazonaws.com/api/v1/user/login", ok: false, …} headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ} status: 502 statusText: "Bad Gateway"
here is my service file code
service.ts
@Injectable()
export class RestService {
baseUrl = environment.baseUrl;
login = this.baseUrl + 'user/login';
constructor(private http: HttpClient) {
}
userlogin(userid, smpassword) {
const params = new HttpParams()
.set('user_id', userid)
.set('sm_password', smpassword);
console.log(params);
return this.http.post(this.baseUrl + 'user/login', params.toString(),
{
headers: new HttpHeaders({
'Content-Type' : 'application/json'
})
}
);
login.component.ts
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
Userlogin: FormGroup;
constructor(private route: Router , private fb: FormBuilder , private rest: RestService) {
this.Userlogin = this.fb.group({
email : ['', [Validators.required , Validators.pattern('^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$') ]],
password : ['', [Validators.required , Validators.minLength(5) ] ]
});
}
// , Validators.required
ngOnInit() { }
login() {
const email = this.Userlogin.get('email').value;
const password = this.Userlogin.get('password').value;
this.rest.userlogin(email, password).subscribe(
result => {
console.log(result);
}
);
// this.route.navigateByUrl('/pendingapproval');
}