Forum Discussion
post request - errors
Hi Vani_metamicro ,
SPHttpClient class getWebUrlFromRequestUrl(requestUrl) method attempts to infer the SPWeb URL associated with the provided REST URL, by looking for common SharePoint path components such as "_api", "_layouts", or "_vit_bin". So, if the requestUrl is "http://example.com/_layouts/service", the returned URL would be "http://example.com".
But here, the url generated is
const postURl = "
";
So, it could not infer any SPWebUrl from it. So, instead of SPHttpClient, use HttpClient class. Also, the flow will be triggered by a HttpRequest.
The modified code is:
private _getListData(): Promise<any> {
const spOpts:IHttpClientOptions= {headers: { 'Content-Type': 'value' }, body:"value" };
const postURl = "
";
return this.context.HttpClient
.post(postURl, HttpClient.configurations.v1, spOpts)
.then((response: any) => {
console.log('Post request is success', response);
return response.json();
});
}
For more info, refer https://docs.microsoft.com/en-us/javascript/api/sp-http/sphttpclient?view=sp-typescript-latest