如果我的问题得到解答,我很抱歉请帮助我。
我得到了:
请求已中止:突出显示的代码上的连接意外关闭。
等待Ur及时回复。
XmlDocument responseXmlDocument = new XmlDocument();
string reqURL = ("https://emea.salesforce.com/services/async/29.0/job/" + sfJobId + "/batch");
//Get BatchId
using (System.IO.Stream responseStream = Post(null, reqURL, sfSessionId, "GET", "text/csv; charset=UTF-8"))
{
responseXmlDocument.Load(responseStream);
batchId = ((((responseStream) != null)) ? responseXmlDocument.GetElementsByTagName("id").Item(0).InnerText : "");
}
这是我的帖子:
public static Stream Post(byte[] bytes, string reqURL, string sfSessionId, string method, string contentType)
{
//Create the request object
HttpWebRequest requestHttp = (HttpWebRequest)WebRequest.Create(reqURL);
//Assign the type of request POST,GET..
requestHttp.Method = method;
//Assign Content Type
requestHttp.ContentType = contentType;
//"text/csv; charset=UTF-8" or "application/xml; charset=UTF-8"
//Assign the session id to the header
requestHttp.Headers.Add(("X-SFDC-Session: " + sfSessionId));
//requestHttp.Headers.Add(requestHttp.ContentType , "text/xml; charset=UTF-8");
requestHttp.KeepAlive = true;
requestHttp.Timeout = 100000000;
requestHttp.ReadWriteTimeout = 100000000;
//Assign byte length
if ((bytes != null))
{
requestHttp.ContentLength = bytes.Length;
System.IO.Stream strmHttpContent = requestHttp.GetRequestStream();
strmHttpContent.Write(bytes, 0, bytes.Length);
strmHttpContent.Close();
}
//Get the response object
String responseFromServer;
try
{
//Call the service and get the response
HttpWebResponse response = (HttpWebResponse)requestHttp.GetResponse();
if (HttpStatusCode.OK == response.StatusCode)
{
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
responseFromServer = reader.ReadToEnd();
response.Close();
}
}
catch (WebException e)
{
using (WebResponse response = e.Response)
{
HttpWebResponse httpResponse = (HttpWebResponse)response;
responseFromServer = string.Format("Error code: {0} ", httpResponse.StatusCode);
using (Stream data = response.GetResponseStream())
{
responseFromServer += new StreamReader(data).ReadToEnd();
// return responseFromServer;
Console.WriteLine("reponse from server" + responseFromServer);
}
}
}
//Return response Stream
WebResponse responseHttpRequest = requestHttp.GetResponse();
return responseHttpRequest.GetResponseStream();
}