0

I am working on application where need to write back to webapi, written below code where on post request passing in body like email ,username but when i write get below error POST unsupported media type i assume it is related to json but not sure what need to be done can any one help me here

POST https://xxxxxxxxxxxxxxx.azurewebsites.net/api/xxxxxx 415 (Unsupported Media Type)
private createitem = (enteredEntityValue: string): void => {
  this.props.context.aadHttpClientFactory
  .getClient('xxxxxx-xxx-xxxxx-xxxx-xxxxxx')
  .then((client: AadHttpClient): void => {
    
    client
      .post('https://xxxxxxxxxxxxxxx.azurewebsites.net/api/xxxxxx', AadHttpClient.configurations.v1,{
      
         body: JSON.stringify({
          "userEmail": this.props.context.pageContext.user.email,
          "userName":this.props.context.pageContext.user.email,
          "Test":enteredEntityValue
        })
         
       })
       
       .then((response: HttpClientResponse) => {

        console.log(response)
        if (response.ok) {
         response.json().then((responseJSON) => {
            console.log(responseJSON);
            alert(`Item created successfully with ID: ${responseJSON.ID}`);
          });
       } else {
         response.json().then((responseJSON) => {
            console.log(responseJSON);
            alert(`Something went wrong! Check the error in the browser console.`);
          });
       }
     }).catch(error => {
       console.log(error);
    });
  
    }); 

  

}
Ashok
  • 59
  • 1
  • 10

0 Answers0