private OpenCartConnector() { LastProcessSuccess = true; if (!Configuration.Current.OpenCartAdminURL.EndsWith("/")) { Configuration.Current.OpenCartAdminURL = Configuration.Current.OpenCartAdminURL + "/"; } try { using (var client = new CookieWebClient()) { var values = new NameValueCollection { { "username", Configuration.Current.OpenCartUsername }, { "password", Configuration.Current.OpenCartPassword }, }; byte[] b = client.UploadValues(string.Format(LoginURLFormat, Configuration.Current.OpenCartAdminURL), values); cookies = client.CookieContainer; string x = System.Text.ASCIIEncoding.UTF8.GetString(b); //token=686fc274c18ff279662a39bc57490c2f' int posstart = x.IndexOf("token="); int posend = x.IndexOf("'", posstart); Token = x.Substring(posstart, posend - posstart); } } catch (Exception ex) { ErrorMessage = ex.Message; LastProcessSuccess = false; } }
private void OnConnect(object sender, RoutedEventArgs e) { var values = new NameValueCollection { { "username", "russ" }, { "password", "1tennesseeb" }, }; //string boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x"); //string formDataHeaderTemplate = Environment.NewLine + "--" + boundary + Environment.NewLine + // "Content-Disposition: form-data; name=\"{0}\";" + Environment.NewLine + Environment.NewLine + "{1}"; //HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://test.deviumrocks.com/admin/index.php?route=common/login"); //request.Method = "POST"; //request.ContentType = "application/x-www-form-urlencoded"; //request.UserAgent = "My goofy little User Agent (Russ Judge)"; //using (MemoryStream ms = new MemoryStream()) //{ // foreach (string key in values.Keys) // { // byte[] formItemBytes = System.Text.Encoding.UTF8.GetBytes(string.Format(formDataHeaderTemplate, // key, values[key])); // ms.Write(formItemBytes, 0, formItemBytes.Length); // } // ms.Position = 0; // request.ContentLength = ms.Length; // using (Stream reqStream = request.GetRequestStream()) // { // byte[] buffer = new byte[1024]; // int bytesRead = ms.Read(buffer, 0, buffer.Length); // while (bytesRead >0) // { // reqStream.Write(buffer, 0, bytesRead); // bytesRead = ms.Read(buffer, 0, buffer.Length); // } // HttpWebResponse response = (HttpWebResponse)request.GetResponse(); // using (StreamReader sr = new StreamReader(response.GetResponseStream())) // { // string result = sr.ReadToEnd(); // } // } //} //upload using (var client = new CookieWebClient()) { byte[] b = client.UploadValues("http://test.deviumrocks.com/admin/index.php?route=common/login", values); string x = System.Text.ASCIIEncoding.UTF8.GetString(b); //token=686fc274c18ff279662a39bc57490c2f' int posstart = x.IndexOf("token="); int posend = x.IndexOf("'", posstart); string token = x.Substring(posstart, posend - posstart); // If the previous call succeeded we now have a valid authentication cookie // so we could download the protected page List<string> files = new List<string>(); files.Add(@"E:\Users\Russ\SkyDrive\Fox One POS\TestExport_20140407.csv"); UploadFilesToRemoteUrl(string.Format("http://test2.deviumrocks.com/admin/index.php?route=report/stock&{0}", token), files.ToArray(), "uploadPos", "application/vnd.ms-excel", new NameValueCollection(), client.CookieContainer, "Upload was succesful"); //HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://test.deviumrocks.com/admin/index.php?route=report/stock&{0}"); //string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x"); //request.CookieContainer = client.CookieContainer; //request.Method = "POST"; //request.ContentType = "multipart/form-data; boundary=" + boundary; //byte[] boundarybytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n"); //b = client.UploadFile(string.Format("http://test.deviumrocks.com/admin/index.php?route=report/stock&{0}", token), ""); //string result = client.DownloadString(string.Format("http://test.deviumrocks.com/admin/index.php?route=report/stock&{0}&uploadPos={1}", token,)); } }
void DownloadPOSUPdate() { var values = new NameValueCollection { { "username", "russ" }, { "password", "1tennesseeb" }, }; using (var client = new CookieWebClient()) { byte[] b = client.UploadValues("http://test.deviumrocks.com/admin/index.php?route=common/login", values); string x = System.Text.ASCIIEncoding.UTF8.GetString(b); //token=686fc274c18ff279662a39bc57490c2f' int posstart = x.IndexOf("token="); int posend = x.IndexOf("'", posstart); string token = x.Substring(posstart, posend - posstart); // If the previous call succeeded we now have a valid authentication cookie // so we could download the protected page string result = client.DownloadString(string.Format("http://test.deviumrocks.com/admin/index.php?route=report/stock&{0}&pos", token)); } }