Answer the question
In order to leave comments, you need to log in
How to make a POST request, a cry from the heart?
Good afternoon!
I make a request through Angular, the source is installed on a certified server. But it gives this error:
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://api3.******/');
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
xhr.responseType = 'json'
xhr.onload = () => {
console.log(xhr.response)
};
xhr.send(JSON.stringify({
"login": "******",
"pass": "*****"
}));
let headers = { headers: new HttpHeaders({'Content-Type': 'application/json; charset=UTF-8'}) }
let body = new HttpParams()
body.set("login", "******")
body.set("pass", "******")
this.http.post<any>('https://api3.******',
body,
headers
).subscribe((data)=>{
console.log(data)
})
Answer the question
In order to leave comments, you need to log in
this.http.post(url, {
login, password
})
Set axios, this is the standard for working with requests
, and what do you have in this.http.post
code, do
you send a request like this?
Zayuzay fetch, look at what gives.
https://developer.mozilla.org/ru/docs/Web/API/Fetc...
On the client write:
import { HttpClient, HttpHeaders } from '@angular/common/http';
export class Твой_класс {
headers = new HttpHeaders();
options = { headers: this.headers, withCredintials: false };
constructor(private http: HttpClient) {}
post(data: any) {
this.http.post('https://........./', data, this.options).subscribe(data => {
console.log('Ответ сервера: ', data);
// Затем смотри, что лежит в data, вероятно просто json поломанный приходит.
// Проверить ответ на корректность можно здесь: http://json.parser.online
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question