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
dmchengdmcheng 

Use PageReference to make a POST request?

I need to mimic an HTML POST form submission and redirect to the same page (non-Visualforce).  Is this possible using PageReference?  the form submission has to be a POST and I don't see any methods on PageReference for setting the  request body.
Best Answer chosen by dmcheng
dmchengdmcheng
I was able to solve the problem without using PageReference.  Basically I created an HTML form on the VF page and use the target parameter on the form tag to open a new window.

All Answers

Naval Sharma4Naval Sharma4
Hi,

Can you let me know what will be the URL for post? Do you want to submit your request to salesforce?
dmchengdmcheng
Hello thanks for your reply. The request is going to an existing HTML web page outside of Salesforce. I don't want to disclose the URL, but it's HTTP, not HTTPS. Right now the form submission is being done from another HTML webpage using an HTML form tag with a POST action.
Naval Sharma4Naval Sharma4
Why dont you prefer using HTTP Request methods on button click instead of using html?
 
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_http_httprequest.htm
dmchengdmcheng
I need to redirect to that page when I make the form submission to it. The page is doing some additional processing based on the form submissions and then it displays the results. If I use HTTP Request and then a setRedirect, I won't get the results displayed because the setRedirect uses GET.
Naval Sharma4Naval Sharma4
Can you put your code here? If you don't want to disclose your URL then replace that with fake URL.
dmchengdmcheng
I was able to solve the problem without using PageReference.  Basically I created an HTML form on the VF page and use the target parameter on the form tag to open a new window.
This was selected as the best answer
Jules Faligot 9Jules Faligot 9
Hello @dmcheng,
I am facing a similar issue, could you share your solution in more details?
dmchengdmcheng
Sure.  I got the input IDs from examining the source of the external form page:
 
<apex:page standardController="Account" showHeader="true" sidebar="true">

	<form id="scan-form" action="http://TheExternalWebSite.com/page" method="post" 
			target="_blank" charset="UTF-8" enctype="application/x-www-form-urlencoded">

		<fieldset>
			<input id="scan-name" name="name" value="{!Account.Name}" />
			<input id="scan-address" name="address" value="{!Account.ShippingStreet}" />
			<input id="scan-zip" name="zip" value="{!Account.ShippingPostalCode}" /> 
			<input id="scan-phone" name="phone" value="{!Account.Phone}" />
			<input type="submit" value="Search" />
		</fieldset>
	</form>
</apex:page>

 
Jules Faligot 9Jules Faligot 9
Awsome, thx a lot!