Reply
Contributor
SuryaCD
Posts: 5
0

How to post data to salesforce

Hi, Can anyone pls help me how to pass the data from webtolead to salesforce in c#.

This is my code. 

protected void btnSubmit_Click(object sender, EventArgs e)
{
Page.Validate();
if (Page.IsValid)
{
StringBuilder data = new StringBuilder();
data.Append("oid=" + oid.Value);
//data.Append("&retURL=" + Server.UrlEncode("http://www.myweb.co/contact/messagesent.aspx"));
data.Append("&retURL=" + retURL.Value);
data.Append("&first_name=" + Server.UrlEncode(first_name.Value));
data.Append("&last_name=" + Server.UrlEncode(last_name.Value));
data.Append("&email=" + Server.UrlEncode(email.Value));

//Post the data
byte[] buffer = System.Text.Encoding.GetEncoding("UTF-8").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);
}
}
}