You need to sign in to do that
Don't have an account?
![Gerald George Gerald George](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Post data from a website form to Salesforce using the web to lead form with asp.net mvc5 for record insertion using c# and mvc controller ? link = https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8"
Below is the code I am using ... I am not sure if this is right.
int debug = 1; // 1 = true
string debugEmail = "erald@ghanafx.com";
StringBuilder data = new StringBuilder();
data.Append("oid=[00D20000000l2qZ]");
data.Append("&retURL=" + HttpContext.Current.Server.UrlEncode("https://secure.ghanafx.com/open-live-account-thanks"));
data.Append("&first_name=" + HttpContext.Current.Server.UrlEncode("Mohsin"));
data.Append("&last_name=" + HttpContext.Current.Server.UrlEncode("Ali"));
data.Append("&email=" + HttpContext.Current.Server.UrlEncode("mohsin_ali_nisar@yahoo.com"));
data.Append("&country_code=" + HttpContext.Current.Server.UrlEncode("AX"));
data.Append("&00N0O00000ALjKl=" + HttpContext.Current.Server.UrlEncode("50"));
data.Append("&00N0O00000ALj57=" + HttpContext.Current.Server.UrlEncode("S/E"));
data.Append("&00N0O00000ALj52=" + HttpContext.Current.Server.UrlEncode("7PM"));
data.Append("&00N0O00000ALj4n=" + HttpContext.Current.Server.UrlEncode("Expert"));
data.Append("&mobile=" + HttpContext.Current.Server.UrlEncode("03319337096"));
data.Append("&phone=" + HttpContext.Current.Server.UrlEncode("05453534"));
data.Append("&title=" + HttpContext.Current.Server.UrlEncode("MOSS"));
data.Append("&debug=" + debug);
data.Append("&debugEmail=" + HttpContext.Current.Server.UrlEncode(debugEmail));
// Post the data
byte[] buffer = Encoding.UTF8.GetBytes(data.ToString());
string url = "https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
buffer = Encoding.UTF8.GetBytes(data.ToString());
req.ContentLength = buffer.Length;
using (Stream reqst = req.GetRequestStream())
{
reqst.Write(buffer, 0, buffer.Length);
}
int debug = 1; // 1 = true
string debugEmail = "erald@ghanafx.com";
StringBuilder data = new StringBuilder();
data.Append("oid=[00D20000000l2qZ]");
data.Append("&retURL=" + HttpContext.Current.Server.UrlEncode("https://secure.ghanafx.com/open-live-account-thanks"));
data.Append("&first_name=" + HttpContext.Current.Server.UrlEncode("Mohsin"));
data.Append("&last_name=" + HttpContext.Current.Server.UrlEncode("Ali"));
data.Append("&email=" + HttpContext.Current.Server.UrlEncode("mohsin_ali_nisar@yahoo.com"));
data.Append("&country_code=" + HttpContext.Current.Server.UrlEncode("AX"));
data.Append("&00N0O00000ALjKl=" + HttpContext.Current.Server.UrlEncode("50"));
data.Append("&00N0O00000ALj57=" + HttpContext.Current.Server.UrlEncode("S/E"));
data.Append("&00N0O00000ALj52=" + HttpContext.Current.Server.UrlEncode("7PM"));
data.Append("&00N0O00000ALj4n=" + HttpContext.Current.Server.UrlEncode("Expert"));
data.Append("&mobile=" + HttpContext.Current.Server.UrlEncode("03319337096"));
data.Append("&phone=" + HttpContext.Current.Server.UrlEncode("05453534"));
data.Append("&title=" + HttpContext.Current.Server.UrlEncode("MOSS"));
data.Append("&debug=" + debug);
data.Append("&debugEmail=" + HttpContext.Current.Server.UrlEncode(debugEmail));
// Post the data
byte[] buffer = Encoding.UTF8.GetBytes(data.ToString());
string url = "https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
buffer = Encoding.UTF8.GetBytes(data.ToString());
req.ContentLength = buffer.Length;
using (Stream reqst = req.GetRequestStream())
{
reqst.Write(buffer, 0, buffer.Length);
}