マルチパートMIME、つまり添付ファイル付きの石鹸を送信するスクリプトがあります。私はC#httpWebRequestクラスを使用しています。コンテンツの長さが必要であるというエラーが表示されますが、webrequestのcontentLengthプロパティを使用してコードでコンテンツの長さを動的に設定しています。なぜこれができるのか、何か考えはありますか?ありがとう!これはコードです:
public void sendSOAPoverHttpVoda()
{
try
{
string xmlDoc = this.soapXml;
byte[] bytes;
bytes = Encoding.UTF8.GetBytes(xmlDoc);
long contentSize = bytes.Length;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(conectionUrl);
req.SendChunked = true;
CredentialCache credentialCacheObj = new CredentialCache();
credentialCacheObj.Add(
new Uri(conectionUrl),
"Basic", new NetworkCredential("dddfff", "dddddd"));
credentialCacheObj.Add(new Uri(conectionUrl), "Digest", new NetworkCredential("dddfff", "dddddd"));
req.Credentials = credentialCacheObj;
req.Method = "POST";
req.ProtocolVersion = HttpVersion.Version11;
req.ContentLength = xmlDoc.Length;
req.ContentType = "multipart/related; boundary=\"----=cellsmart_mm7_SOAP\";type=\"text/xml\";Start=\"</cellsmart_mm7_submit>\"";
req.AllowWriteStreamBuffering = true;
req.Timeout = 20000;
req.Headers.Add("SOAPAction", "");
//req.Connection = "";
if (bytes != null)
{
using (Stream outputStream = req.GetRequestStream())
{
outputStream.Write(bytes, 0, xmlDoc.Length);
}
}
using (HttpWebResponse response = (HttpWebResponse)req.GetResponse())
{
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
string responseText = reader.ReadToEnd();
Console.WriteLine("Response received from URI : " + responseText);
Console.ReadLine();
}
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine("Error : " + ex.Message + "\n" + ex.StackTrace);
Console.ReadLine();
}
}
私が得るエラー/例外は必要な長さです(411)