function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JPClark3JPClark3 

Http Post to a Site VF Page

I have a requirement to allow third party lead providers to post XML lead data to our application and convert that into a custom object. I currently have it working by having the test client application attach the XML string as a query parameter:

(&leaddata=< ... xml ... />), and sending the httprequest without anything in the body of the post.

 

However, I don't think this is the expacted (or correct) way to post data to the site page. I would think the correct method would be to add the XML in the body of the "POST". The page controller uses the "getParameters()" method then uses the XML Dom to parse the XML. Everything works well after that.

 

My question is:

How would I get hold of the incomong HTTPRequest in the page controller to grab the body of the request?

 

I would expect something like this:

 

public MyController
{
  private string XmlString;
  public MyController()
  {
    HTTPRequest IncomingRequest = Pages.CurrentPage.GetRequest();
    Blob BodyBlob = IncomingRequest.getBody();
    XmlString = BodyBlob.ToString();
  }
}

 

Best Answer chosen by Admin (Salesforce Developers) 
hemantgarghemantgarg

You can get the variables in the same way as in get request parameters like :-

 

value = ApexPages.currentpage().getParameters().get('<NAME OF POST PARAM>');

All Answers

hemantgarghemantgarg

To hold the variables you have to maintain the session across tha pages on which you want them, whenever you redirect to other page do it by setRedirect(false) , Also use the same controller in all the pages.

JPClark3JPClark3

But how do I get the body of the POST request?

I know how to hold on to values between pages, however, I'm not changing pages. I am accepting a Post.

hemantgarghemantgarg

You can get the variables in the same way as in get request parameters like :-

 

value = ApexPages.currentpage().getParameters().get('<NAME OF POST PARAM>');

This was selected as the best answer
JPClark3JPClark3

Yes. I've been experimenting, and that looks like the way things are working.

So, on the apex controller, it works the same if it is a "Get" request or a "Post".

 

Thanks for your reply.