Results 1 to 6 of 6

Thread: C#, Stream ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Nuclear's Avatar
    Join Date: Sep:2004
    Location: , . ()
    Posts: 3,352

    C#, response ( )?

    .
    Stream .
    ., Stream, StreamReader StreamWriter .
    StreamReader StreamWriter, :

    Code:
    StreamReader readfl  = new StreamReader("e:\\1142.rar");
     StreamWriter writefl = new StreamWriter("e:\\1142out.rar");
     String filecontents = readfl.ReadToEnd(); 
     writefl.Write (filecontents);
     readfl.Close();
     writefl.Close();
    1142.rar 1142out.rar.
    1142.rar 3MB. 1142out.rar 5.6MB. . ?
    Last edited by Nuclear; 7th September 2010 at 21:47. Reason: topic change
    . HWBG !

  2. #2
    XaMaB's Avatar
    Join Date: Nov:2001
    Location:
    Posts: 20,387
    binary
    : XaMaB; . 0.42

    In God we Trust (all others must submit a X.509 certificate). , ()

  3. #3
    Registered User
    Join Date: Dec:2007
    Location: Sofia
    Posts: 366
    FileStream.

  4. #4
    Nuclear's Avatar
    Join Date: Sep:2004
    Location: , . ()
    Posts: 3,352
    , Stream , .
    :

    .
    ., , . Submit , , .

    . C# - , , response - , . , .

    , :

    Code:
        public static void UploadFileEx(string uploadfile, string url, CookieContainer cookies)
            {           
                   
                string fileFormName = "file";
                string  contenttype = "application/octet-stream";            
                string postdata="?";
                Uri uri = new Uri(url + postdata);
                
                string boundary = "----------" + DateTime.Now.Ticks.ToString("x");
                HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(uri);
                webrequest.CookieContainer = cookies;
                webrequest.ContentType = "multipart/form-data; boundary=" + boundary;
                webrequest.Method = "POST";
    
    
                // Build up the post message header
    
                StringBuilder sb = new StringBuilder();
                sb.Append("--");
                sb.Append(boundary);
                sb.Append("\r\n");
                sb.Append("Content-Disposition: form-data; name=\"");
                sb.Append(fileFormName);
                sb.Append("\"; filename=\"");
                sb.Append(Path.GetFileName(uploadfile));
                sb.Append("\"");
                sb.Append("\r\n");
                sb.Append("Content-Type: ");
                sb.Append(contenttype);
                sb.Append("\r\n");
                sb.Append("\r\n");
    
                string postHeader = sb.ToString();
                byte[] postHeaderBytes = Encoding.UTF8.GetBytes(postHeader);
    
                // 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");
    
                if (!System.IO.File.Exists(uploadfile))
                {
                    MessageBox.Show("file not found");              
                }
                FileStream fileStream = new FileStream(uploadfile, FileMode.Open, FileAccess.Read);
                long length = postHeaderBytes.Length + fileStream.Length + boundaryBytes.Length;
                webrequest.ContentLength = length;
    
                Stream requestStream = webrequest.GetRequestStream();
    
                // Write out our post header
    
                requestStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);
    
                // Write out the file contents
    
                byte[] buffer = new Byte[checked((uint)Math.Min(4096,(int)fileStream.Length))];
                int bytesRead = 0;
                while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)requestStream.Write(buffer, 0, bytesRead);
    
                // Write out the trailing boundary
    
                requestStream.Write(boundaryBytes, 0, boundaryBytes.Length);
                try
                {
                    WebResponse resp = webrequest.GetResponse();
                    Stream s = resp.GetResponseStream();
                   int readr = 0;
                    byte[] buffer1 = new byte[32767];
                    FileStream outff = new FileStream(uploadfile + "outsf", FileMode.Create);
    
                    while (true)
                    {
                        readr = s.Read(buffer1, 0, buffer1.Length);
                        if (readr <= 0) break;
                        outff.Write(buffer1, 0, buffer1.Length);
                    }
                    
                    outff.Close();
                 }
                catch (WebException e)
                {
                        MessageBox.Show(e.Message);
                }
               
                
            }
    /Hidden:


    , exception "no response. The connection timed out" "WebResponse resp = webrequest.GetResponse();"
    , .

    , ( upload ), .

    Code:
    <form method='post' enctype='multipart/form-data'>
            file to upload: <input type=file name='upfile'><br>
            <input type=submit value='submit'>
    
        </form>
    /Hidden: file upload form


    . decoder.py decoder.py ( ). , , .
    - upload , POST .

    , ( sniffer) , , .

    , , (1. php ( ), 2. php script ( header("Content-Type: application/octet-stream;"))) .
    . HWBG !

  5. #5
    Teh AimeR AimeR's Avatar
    Join Date: Dec:2006
    Location: //
    Posts: 4,307
    , , web- ...
    HttpWebRequest.TimeOut - .

    , , upload- e web application. Upload-a file . entry- web.config-a upload-a :

    Code:
    <configuration>
    ...
    <system. web>
      <httpRuntime maxRequestLength="102400" executionTimeout= "3600" />
      ...
    </system .web>
    <system.webServer>
    ...
       <security >
         <requestFiltering>
           <requestLimits maxAllowedContentLength="1024000000" />
         </requestFiltering>
       </security>
    </system.webServer> 
    </configuration>
    /Hidden: Web.config settings for 100MB maximum request length and 1 hour execution timeout
    Last edited by AimeR; 7th September 2010 at 23:17.
    ASUS X570-P|R7 5800X3D@NH-U14S|2X16G DDR4 3200 Corsair VENGEANCE LPX|Samsung 980 PRO 1TB|Radeon RX 7900 XTX 24G|AOC CQ32G1|Corsair RM750x|CM 693

  6. #6
    Nuclear's Avatar
    Join Date: Sep:2004
    Location: , . ()
    Posts: 3,352
    , , . ( ).
    Application, .

    upload .

    EDIT: , - Wireshark request ( ). , - .

    ---------- 16:06 ---------- 10:31 ----------

    , .
    Wireshark , :
    1. "HTTP/1.1 100 Continue". , , "ServicePointManager.Expect100Contin ue = false;" .
    2. ( ).
    :
    Code:
    ------------------------------8cd1d73689cb354
    2 .
    3. , Incorrect Input.
    . .
    Last edited by Nuclear; 8th September 2010 at 11:06.
    . HWBG !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |