我试图连接到SalesForce.com批量API,因此我可以从我的应用程序批量上传数据。我已经通读了PDF documentation,它强调使用CURL来发出POST请求。按照说明,我创建了一个XML格式的文本文件,用于登录到服务器。下面使用C#连接到SalesForce批量API
的login.txt内容:
<?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;
httpRequest = HttpWebRequest)WebRequest.Create("https://login.salesforce.com/services/Soap/c/20.0");
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();
}
当这个代码执行我总是得到500错误。有没有人有任何经验来做我想做的事情?你能否给我提供一些建议?
预先感谢您。
我怎样才能读取响应?只要.GetResponse()被调用,它就会将我的请求传给我的catch块,并使用通用500异常,它没有InnerException。 – Adam 2010-12-01 18:46:25