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

Web-To-Lead form - does it need headers?

I'm trying to use an aspx page which have a HttpWebRequest to submit the form. Instead of having the user submit the form to send the information. This is because I want to send all leads collected in the website once a day reading from our database.

When I run the form, which have the action to go to salesforce applet, by typing the URL in a new browser (http://localhost/salesforce_form.aspx? it works perfect (create the lead in SF), but when I run the form using (HttpWebRequest) WebRequest.Create(sCreateURL); it doesn't create the lead. This is my code in the page that I want to run once a day (I'm just testing creating one lead, then I will change it to have the request within a loop to send all leads.
string sCreateURL = "http://localhost/salesforce_form.aspx?";
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(sCreateURL);
req.ContentType = "application/x-www-form-urlencoded";
req.UserAgent = "Mozilla%2f4.0+(compatible%3b+MSIE+6.0%3b+Windows+NT+5.1%3b+SV1%3b+.NET+CLR+1.1.4322)";
HttpWebResponse res = (HttpWebResponse) req.GetResponse();
I will appreciate any help on this issue
I don't see any code that's hitting a server, so i'm not sure how we can help you, this seems to be an issue with the aspx page you built.
The logic is this:
Is within the "salesforce_form.aspx" where I have:
form ID="Form1" name="Form1" enableValidation="true" language="javascript" method="post" action=
I load the lead information within this page usign the parameter sEmail and at the end with javascript I submit the form automatically.
I was testing the code I sent you and it works if I print the "htmlContent" where I get the stream. The problem is that if I print the stream, it won't let me to tun the webrequest again for the next lead email

string htmlContent = resStream.ReadToEnd();



Response.Write (htmlContent);

Thanks for your help


All that does is write out the HTML for a form. Do you have some javascript that auto submits it? if so this isn't going to work,. HttpWebRequest just makes a HTTP request for the content, its not a browser, it will not run the javascript to trigger the form posting.

If you're doing a batch operation, why don't you just write a console app that reads your data and uses the API to create the Leads, and run it from the windows scheduler.

I sent the previous reply withouth ending my response.

Just in case the logic is this:

salesforce_form.aspx has the form using the code provided by salesforce to create the leads from the web. It's here where I include action= "...salesforce applet.."

salesforce_getleads.aspx is the page where I want to read all leads collected during the day in my website and then create a loop where I send the salesfroce_form.aspx for each lead. It's here where I have the WebRequest for salesforce_form.aspx?

Thanks for your attention. I'll appreciate any help on this issue



Thanks for your help, I did you you recommend me and it's working. But now I have a problem in the values of a picklist (with multiple values selection). As I mentioned before I'm using the Web-To-Lead code to create the leads in SF. How do I send multiple values? I'm using ";" but it doesn't work. It send the whole string "value1;value2;..." (it even cuts the text)

I hope you can help me with this.