You need to sign in to do that
Don't have an account?
paul-lmi
More code samples on http, httprequest, and httpresponse
The documentation only really has a code sample for a simple GET request. This may be fine for some, but I'm lost on how to properly set up a standard POST request, specifically, setting header and body info.
a few more helpers
hope this helps.
by the way, where would you recommend i submit this class when i'm done? I'm building a class to allow integration with defensio.com's spam filtering/checking API, so I'm sure it'll help quite a few that want to add some data checks to their triggers before actually inserting data.
private Map<String,String> headers = new Map<String, String>{};
public void setHeaders(Map<String, String> h) {headers = h.clone();}
feel free to contribute to a force.code.share project, if you are interested, send me a note and I can add you as a contributor.
This is the project that i've begun to build:
http://code.google.com/p/visualforce-components/
click join project and we should be able to add you.
On your suggested use, you cannot make callouts from a trigger, the issue is database locking, in a trigger there is a transaction inflight. This is not compatable with a callout, which has a timeout of 10 seconds. Delaying a save or update by 10 seconds is no way to run a database.
You can create a simple button that makes the callout and marks the offending records as spam, and deletes them or moves them into a queue.
I would love to look over your code when it's running.
you think they'd let me take a vacation after....:)
so when i build this request as a POST request instead of a GET, am I just building the full URL string as the endpoint?
example: (the global__c stuff is may way of storing global variables in SFDC itself without hard coding them)
and then:
I'm sure that's wrong or at least there's a better way I'm not aware of. Forgive my newness, I'm a networking guy, not a web dev, so I'm not sure how I'm supposed to pass the params to the endpoint as a POST. Are the parameters supposed to be part of the body itself? In my reading it states that POST variables are supposed to be sent as part of the request, and are seperated from the headers by a blank line.
Once we're good here, I think I'll write a pretty example of POST and have you guys add it to the example in the Apex Developer's Guide.
placing the name=values on the url, or in the body (newline seperated?)
so, normal endpoint, then something like
req.setBody("myparam=myValue1\nmyparm2=myvalue2");
you may find that when you write a testMethod for this, you are not able to make the actual callout (from a testMethod), this is a limitation.
instead, i normaly write a simple (public static) wrapper method that i can call from the execute Anonomous window to test the callouts i've written.
to set POST parameters, you set body equal to:
param1=value¶m2=value¶m3=value
i had to dissect an HTML form POST with Wireshark to figure that one out, lol
Hi all/paul-lmi,
I tried to set the body as a a "param1=value¶m2=value¶m3=value" string, an html form, and a full html, but the system receiving my http post is still not recognizing my post.
Could anyone please help? Below is my code. Thank you very much!!! I am totally stuck....
===============================
String theMessage = 'userid='+'xyz.test@xyz.com'+'&password='+ 'test123' + '&SAMLRequest=' + request;
HttpRequest req = new HttpRequest();
req.setEndpoint('http://xyz.com/myserver/authorization/AuthenticationServlet');
req.setMethod('POST');
req.setHeader('Content-Type', 'text/html');
req.setBody(theMessage);
Http h = new Http();
HTTPResponse res;
res = h.send(req);
To post a form, you need to use the correct content-type of application/x-www-form-urlencoded