i am sending a GET request to a spring boot backend api, but i keep getting a 405 error, POST method not allowed
my code is
public class TextingSolution {
private final Contact xReceiver {get;set;}
public String MessageContent{get;set;}
public Boolean Success {get;set;}
// public integer reloadTime ;
public TextingSolution(ApexPages.StandardController controller){
Id xId= System.currentPageReference().getParameters().get('Id');
this.xReceiver = [Select Name, Phone From Contact Where Id=:xId];
}
public void ClosePopUp(){
this.Success = false;
}
public void showPopUp(){
this.Success = true;
}
public PageReference SendMessage(){
// perform Apex Callout Here
String jsonBody = '{"phoneNumber":' +JSON.serialize(this.xReceiver.Phone) +', "text":'+ JSON.serialize(this.MessageContent)+'}';
System.debug(jsonBody);
PageReference page = ApexPages.currentPage();
Http http = new Http();
HttpRequest Request = new HttpRequest();
//configure request
Request.setEndpoint('http://3.19.59.9:8080/api/v1/sendMessage');
Request.setHeader('Content-Type', 'application/json');
Request.setBody(jsonBody);
Request.setMethod('GET');
system.debug(request);
// send request, get response!
HttpResponse Response = http.send(Request);
System.debug('Response: ' + Response.getBody());
//if(Response.getStatusCode()==200){
// this.Success= true;
//System.debug('Successful: '+ this.Success);
page.setRedirect(true);
//}else this.Success = false;
return page;
}
}
but i get this response in the Debug
10:35:20:105 USER_DEBUG [43]|DEBUG|Response: <html><body><h1>Whitelabel Error Page</h1><p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p><div id='created'>Mon Nov 18 09:35:20 UTC 2019</div><div>There was an unexpected error (type=Method Not Allowed, status=405).</div><div>Request method 'POST' not supported</div></body></html>
somehow, the web api is seeing my request as a POST request. When i tested in PostMan with a get request, it worked, while with post request i got the error 405. any fixes ??