Hello,
using C#, I'm trying to integrate my web store w/ an email marketing client. I want to upload a comma delimited file of subscribers once a night. They say to get this to work, it has to be a form posts: multipart/form-data, but I'm not using a form. I'm able to connect to their servers but I keep getting back a Data can't be blank. Can anyone help me to get this working?
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;
}