I need to send a single parameter to an IP Address and port within a local network. When using Postman, I achieve this by sending a POST request with the URL 192.168.4.2:80/?led=1. This transmits the parameter led=1 to the specified IP address and port. My goal is to replicate this operation using Angular's HTTP Client, but I'm uncertain about whether or not to include headers. In my Postman setup, I do not utilize Headers when sending the URL, so I am unsure if they are necessary in HTTPClient. Additionally, I prefer to only provide a URL (192.168.4.2:80/?led=1), but encounter an error if omitting parameters.
Below is the code I have developed thus far:
sendData (myNumber) {
//var headers = new Headers();
//let headers = new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded' });
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded'
})
};
console.log(this.http.post('http://192.168.4.2:80/','led=1', httpOptions).subscribe(data=>console.log(data)))
}
My fundamental questions include: 1. Am I succeeding in achieving my desired outcome? 2. Is it possible to purely send a URL POST request in Angular, or must it always include parameters and headers? I presume that the function handles some string processing internally, but uncertainty lingers regarding its ultimate effectiveness. In addition, is there a method to track what HTTPClient is transmitting to the server (i.e. the final product)? Thank you in advance!