You need to sign in to do that
Don't have an account?
Call web service using POST help needed!!
Hi all, I have problems calling a web service using the POST method. I think that I have the idea of how to do it...:S but Im not sure. Here is my code
public static String sendContent(String url,String parameters)
{
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(url); //this is the http://myws/
req.setMethod('POST');
req.setBody(parameters);this is like parameters="var1=value1&var2=value2&var3=value3"
req.setHeader('Content-type', 'application/x-www-form-urlencoded');
req.setHeader('Content-length', String.valueOf(parameters.length()) );
HttpResponse res = h.send(req);
return res.getBody();
}
Now when i execute this the res.getBody() throws me the following error:
<?xml version='1.0' encoding='ISO-8859-1' ?> <SOAP-ENV:Envelope> <SOAP-ENV:Body> <SOAP-ENV:Fault> <faultcode>SOAP-ENV:Server</faultcode> <faultstring>Unknown exception</faultstring> <faultactor>server name:listen port</faultactor> <detail><appSpecific>Unknown Exception has occurred</appSpecific> </detail> </SOAP-ENV:Fault> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
I don't really know if I'm setting the headers correctly or what is missing so Ill really appreciate your help.
Thank you for your time
http://blog.jeffdouglas.com/2009/03/16/restful-web-service-callout-using-post/
Jeff Douglas
Appirio
http:blog.jeffdouglas.com
is the an error being thrown by SF, or just the response to your callout? try throwing
system.debug('response: ' + res);
into your code to debug.
You are getting back a SOAP Fault from the external server.
So it seems you are doing a form POST to a soap web service
endpoint. You will have to construct and send a soap request.