I am trying to post one of the form data to specific server which is CORS disabled that means it will only accept POST method and dis-allowed OPTIONS preflight request which is completely understandable but one of the post says that if request is Simple Request (POST with content type =application/x-www-form-urlencoded, )it should not create problem but i am still getting error of
Actual Error on console..
Access to XMLHttpRequest at 'https://****.****.com/hpm/launchTransnoxScreen.hpm' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
--
Could you please help me identify the issue ? I am completely new to angular and just started exploring.
Why is an OPTIONS request sent and can I disable it?
Already checked above URL
import { Injectable } from '@angular/core';
import { Patient } from '../model/patient';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class SignupService {
private url: string = "https://stagemc.transnox.com/hpm/launchTransnoxScreen.hpm";
private httpHeadersVar = {
headers: new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'text/html'
})
};
patientFormData: Patient;
constructor(private http: HttpClient) { }
callThP(data) {
const formData = new FormData();
formData.append('myKey1', 'some value 1');
formData.append('myKey2', 'some value 2');
formData.append('myKey3', 'true');
this.http.post(this.url, formData, this.httpHeadersVar).subscribe(
(res) => {
console.log(res);
},
err => console.log(err)
);
}
}
Below sample of html is working fine individually when we clicked on button.
It connects to host and revert with sample page.
<html>
<head></head>
<body>
<form id="hppForm" name="hppForm" method="POST" action=" https://stagecp.transnox.com/hpm/launchTransnoxScreen.hpm">
<input name="uniqueID" id="uniqueID" type="hidden" value="XXX3" />
<input name="deviceID" id="deviceID" type="hidden" value="test_deviceID"/>
<button type="submit" class="btn btn-primary btn-block">Sign up</button>
</form>
</body>
</html>