I am trying to connect to the SalesForce.com bulk API so I can do mass uploads of data from my application. I have read through the PDF documentation which emphasizes using CURL to make the POST requests. In keeping with the instructions, I have created a text file in XML format which is used for logging into the server.
<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<n1:login xmlns:n1="urn:partner.soap.sforce.com">
<n1:username>my username</n1:username>
<n1:password>my password</n1:password>
</n1:login>
</env:Body>
</env:Envelope>
XmlDocument XMLResponse = null;
HttpWebRequest httpRequest;
HttpWebResponse httpResponse = null;
Stream requestStream = null;
Stream responseStream = null;
XmlTextReader xmlReader;
try
{
byte[] bytes = File.ReadAllBytes(filename);
httpRequest.Method = "POST";
httpRequest.ContentLength = bytes.Length;
httpRequest.ContentType = "text/xml; charset=UTF-8";
httpRequest.Headers.Add("SOAPAction: login");
requestStream = httpRequest.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
httpResponse = (HttpWebResponse)httpRequest.GetResponse();
if (httpResponse.StatusCode == HttpStatusCode.OK)
{
responseStream = httpResponse.GetResponseStream();
xmlReader = new XmlTextReader(responseStream);
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(xmlReader);
XMLResponse = xmldoc;
xmlReader.Close();
}
httpResponse.Close();
}