I am in the process of updating the UX for an older application with APIs developed in ASP.NET
When I make a POST request as shown below, everything works perfectly. The data is received:
var APIURL = sessionStorage.getItem('endpoint') + "/api/setplid.aspx";
var options = { headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded') };
var body = new URLSearchParams();
body.set('plid', encodeURIComponent(sessionStorage.getItem('plid')));
body.set('userkey', encodeURIComponent(sessionStorage.getItem('userkey')));
body.set('sessionkey', encodeURIComponent(sessionStorage.getItem('sessionkey')));
this.httpClient.post(APIURL, body.toString(), options).subscribe(
result => {...
Now, however, I need to upload a file. So, I modified my code to the following:
var APIURL = sessionStorage.getItem('endpoint') + "/api/setplid.aspx";
let options = { headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded') };
let formData = new FormData();
formData.append("plid",encodeURIComponent(sessionStorage.getItem('plid')));
formData.append("userkey",encodeURIComponent(sessionStorage.getItem('userkey')));
formData.append("sessionkey",encodeURIComponent(sessionStorage.getItem('sessionkey')));
formData.append("myfile", this.weblogo,this.weblogo.name);
this._httpClient.post(APIURL, formData, options).subscribe(
result => {...
I checked with the API developers on how they are retrieving the data, and they mentioned using request.form / For example, request.form("plid"), etc. They claim to be receiving no values when using request.form
I am trying to determine if the issue lies with me or them, or if there is a mistake in my httpClient.Post method
Thank you.