C# を使用して、Web ストアをメール マーケティング クライアントと統合しようとしています。購読者のコンマ区切りファイルを 1 晩に 1 回アップロードしたいと考えています。彼らは、これを機能させるには、フォームの投稿である必要があると言います: multipart/form-data ですが、私はフォームを使用していません。私は彼らのサーバーに接続できますが、データを空白にすることはできません. 誰でもこれを機能させるのを手伝ってもらえますか?
public static string Create()
{
string authInfo = "username" + ":" + "password";
string root = AppDomain.CurrentDomain.BaseDirectory;
string file = root + "Folder\\work.txt";
FileInfo fi = new FileInfo(file);
int fileLength = (int)fi.Length;
FileStream rdr = new FileStream(file, FileMode.Open);
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.Accept = "application/xml";
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
httpWebRequest.Headers["Authorization"] = "Basic " + authInfo;
byte[] requestBytes = new byte[fileLength];
int bytesRead = 0;
httpWebRequest.ContentLength = requestBytes.Length;
using (Stream requestStream = httpWebRequest.GetRequestStream())
{
while ((bytesRead = rdr.Read(requestBytes, 0, requestBytes.Length)) != 0)
{
requestStream.Write(requestBytes, 0, bytesRead);
requestStream.Close();
}
}
//READ RESPONSE FROM STREAM
string responseData;
using (StreamReader responseStream = new StreamReader(httpWebRequest.GetResponse().GetResponseStream()))
{
responseData = responseStream.ReadToEnd();
responseStream.Close();
}
return responseData;
}