You need to sign in to do that
Don't have an account?
Alaa
Apex Http callout error : Invalid HTTP method
I have an apex code in which am using the HTTP class to call a PHP page in external server and getting the following error all the time: "Invalid HTTP method"
when I open the page in a web broswer it opens and I can see the output so why am geting this error in the apex class , any idea?
Can you post the code?
Http h = new Http();
// Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
String url='http://tools.xxxxxxx.com/xxxxx/xxxx.php';
HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod(url);
// Send the request, and return a response
HttpResponse res = h.send(req);
String str=res.getBody();
sorry I've just notieced am putting wrong vale in the setMethod :) so now that on is fixed but am getting new error ... am trying to update opportunity description with the resposne am receiveing from this HTTP call and getting the following error:
First error: Update failed. First exception on row 0 with id 006M00000026BVNIA2; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, cloudswarm.opptySwarm: execution of AfterUpdate
caused by: System.AsyncException: Future method cannot be called from a future method: cloudswarm.SwarmHelper.evaluateOpptyRules(LIST<Id>)
(cloudswarm): []
Class.OppDateTest.updateOppDate: line 22, column 7
External entry point
@future(callout=true)
public static void updateOppDate() {
Http h = new Http();
// Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
String url='http://tools.xxxxx.com/xxxxxxxx/xxxxxxx.php';
HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('GET');
// Send the request, and return a response
HttpResponse res = h.send(req);
String str=res.getBody();
Opportunity[] opp = [SELECT id, name FROM Opportunity where name='test'];
for (Opportunity o : opp) {
o.description = str;
update o;
}
}
}
Find below a sample working code of Http request :
Http h = new Http();
HttpRequest req = new HttpRequest();
String url = 'https://api-3t.sandbox.paypal.com/2.0/';
String doRequest;
doRequest = '<soap:Envelope xmlns:soap=' + '\'' + 'http://schemas.xmlsoap.org/soap/envelope/' + '\'' + ' xmlns:xsi=' + '\''+ 'http://www.w3.org/2001/XMLSchema-instance' + '\'' + ' xmlns:xsd=' + '\''+ 'http://www.w3.org/2001/XMLSchema' + '\'' + '></soap:Envelope>';
req.setBody(doRequest);
req.setEndpoint(url);
req.setMethod('POST');
req.setHeader('Content-length', '1753' );
req.setHeader('Content-Type', 'text/xml;charset=UTF-8');
req.setHeader('SOAPAction','');
req.setHeader('Host','api-aa.sandbox.paypal.com');
HttpResponse res = h.send(req);
String xml = res.getBody();
rawResponse = xml;
Hope this helps.
the HTTP request itself is working now but the issue is the with the trigger itself this code is running in trigger on opportunity update and inside this code am updating the opportuninty so am getting this error... so do you know what does it mean?