Sending leads from a site powered by ASP.net

To send leads in from a lead form's backend code, you would generate a POST XML and write that string to the desired POST URL.

For Example (C#):

public string GeneratePost()
{
    string xmlString = @"<Leads vid=""1234"" lid=""1234"" aid=""1234"">
                            <Lead reference=""ABC1234"">
                                <FirstName>John</FirstName>
                                <LastName>Doe</LastName>
                                <Email>noemail@leads.com</Email>
                            </Lead>
                         </Leads>";

    ASCIIEncoding encoding = new ASCIIEncoding();
    byte[] data = encoding.GetBytes(xmlString);

    string deliveryAddress = "http://leads.leadexec.net/processor/insert/general";

    HttpWebRequest RequestObj = (HttpWebRequest)WebRequest.Create(deliveryAddress);
    RequestObj.Method = "POST";
    RequestObj.ContentType = "text/xml";
    RequestObj.ContentLength = data.Length;
    
    Stream RequestStream = RequestObj.GetRequestStream();
    RequestStream.Write(data, 0, data.Length);
    RequestStream.Close();
    
    HttpWebResponse HttpResponse;
    HttpResponse = (HttpWebResponse)RequestObj.GetResponse();
    
    Stream streamResponse = HttpResponse.GetResponseStream();
    StreamReader streamRead = new StreamReader(streamResponse);
    
    return streamRead.ReadToEnd();
}
In the example above, the example POST XML is first encoded and then is sent through the request stream to the POST URL. The response is then received and would then be processed to determined the desired action depending on the sending page's requirements and method sent to.


Copyright ©2012