Exemplo n.º 1
0
        public SubmitFileRequestItem AddSubmitFile(string fileName, string fieldName)
        {
            SubmitFileRequestItem item = new SubmitFileRequestItem(fileName, fieldName);

            this.Add(item);
            return(item);
        }
Exemplo n.º 2
0
        public string BlockingPerform()
        {
            //inform subscribers that we have started
            if (onStart != null)
            {
                onStart();
            }

            http = new Http();
            HttpRequest req = new HttpRequest();

            http.Request = req;

            MemoryStream res = new MemoryStream();

            try
            {
                SubmitFileRequestItem i = req.Items.AddSubmitFile(m_filename, m_labelname);
                i.AddDataArray(m_buffer);
                http.SendProgress += http_SendProgress;
                http.Post(m_url, req, res);
                http.SendProgress -= http_SendProgress;
            }
            catch
            {
            }

            http.Close();

            res.Position = 0;
            StreamReader sr = new StreamReader(res);

            string response = sr.ReadToEnd();

            if (onFinish != null)
            {
                onFinish(response, null);
            }

            return(response);

/*
 *          string boundary = "----------" + DateTime.Now.Ticks.ToString("x");
 *
 *          HttpWebRequest webrequest = (HttpWebRequest) WebRequest.Create(m_url);
 *
 *          webrequest.ContentType = "multipart/form-data; boundary=" + boundary;
 *          webrequest.Method = "POST";
 *
 *          //create our post header
 *          byte[] postHeaderBytes = Encoding.UTF8.GetBytes(m_createPostFunc());
 *
 *          //TODO
 *          //perhaps some form of validation here? or should this be done in the
 *          //validate method
 *
 *          // Build the trailing boundary string as a byte array
 *          // ensuring the boundary appears on a line by itself
 *          byte[] boundaryBytes =
 *              Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");
 *
 *          webrequest.ContentLength = postHeaderBytes.Length + m_buffer.Length +
 *                                     boundaryBytes.Length;
 *
 *          Stream requestStream = webrequest.GetRequestStream();
 *
 *          // Write out our post header
 *          requestStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);
 *
 *          // Write out the post data to our request stream
 *          do
 *          {
 *              int writeAmount = Math.Min(m_bufferSize,
 *                                         (int) (webrequest.ContentLength - requestStream.Position)
 *                  );
 *
 *              requestStream.Write(m_buffer, 0, writeAmount);
 *
 *              //update subscribers
 *              if (onUpdate != null)
 *                  onUpdate(this, Convert.ToDouble(requestStream.Position)/
 *                                 Convert.ToDouble(webrequest.ContentLength)
 *                      );
 *          } while (requestStream.Position < webrequest.ContentLength);
 *
 *          // Write out the trailing boundary
 *          requestStream.Write(boundaryBytes, 0, boundaryBytes.Length);
 *
 *          WebResponse response = webrequest.GetResponse();
 *          Stream s = response.GetResponseStream();
 *
 *
 *
 *
 *          string res = sr.ReadToEnd();*/
        }