Filesonic, Upload pliku poprzez POST (C# 2010 Express)

0

Witam. Otóż mam problem z wysyłaniem POST zapytania na upload pliku w serwisie Filesonic.com. Chcialbym wyslac plik na swoje konto. Po przeskanowaniu wysylaniu pliku na serwer HttpAnalyzerStd6 otrzymalem takie dane:

HEADERS:

Request Headers  Value                                                                                                             
(Request-Line)   GET / HTTP/1.1                                                                                                                     
User-Agent       Opera/9.80 (Windows NT 6.1; U; ru) Presto/2.7.62 Version/11.01                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
Host             www.filesonic.com                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
Accept           text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
Accept-Language  ru-RU,ru;q=0.9,en;q=0.8                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
Accept-Charset   iso-8859-1, utf-8, utf-16, *;q=0.1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
Accept-Encoding  deflate, gzip, x-gzip, identity, *;q=0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
Referer          http://www.filesonic.com/                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
Cookie           isJavascriptEnable=1; tarea=0; user_settings=a%3A1%3A%7Bs%3A26%3A%22intelligence_worldmap_type%22%3Bs%3A9%3A%22downloads%22%3B%7D; fromDate=1299711600; toDate=1301180400; lang=en; fs_orderBy=name; fs_orderDirection=asc; PHPSESSID=s31rg6jminu0t5algecgfugre0; visitSourceUrl=http%3A%2F%2Fwww.hq-uploads.com%2Fsearch%2Fc-filesonic-upload%2F; lastUrlLinkId=353397801; __utmz=26991146.1301270417.94.2.utmcsr=hq-uploads.com|utmccn=(referral)|utmcmd=referral|utmcct=/search/c-filesonic-upload/; email=semixorsonic%40gmail.com; nickname=override; isAffiliate=1; role=free; __utma=26991146.912572680.1300893818.1301273509.1301320319.96; __utmc=26991146; __utmb=26991146.5.10.1301320319  
Cookie2          $Version=1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
Connection       Keep-Alive, TE                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
TE               deflate, gzip, chunked, identity, trailers                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

POSTDATA:

MimeTyp:multipart/form-data  Size: jakis rozmir pliku
folderId = 0
files[] = jakis plik                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      FileName  Attributes  Size  
folderId        0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          1     
files[]         MZђ       яя  ё       @                                   р   є ґ	Н!ёLН!This program cannot be run in DOS mode.$       юJ";є+Lhє+Lhє+Lhє+MhZ+LhіSЯhі+LhіSЩhµ+LhіSПhк+LhіSЮh»+LhіSИhN+Lhќн2h»+LhіSШh»+LhіSЭh»+LhRichє+Lh                PE  L »mJ        а !
	  ц  &     –^                           P    !П  @                   °Щ &,  мК d    p             И X   Ђ \ї                                ђѓ @                                        .text   Цх     ц                   `.data   ДP    ъ   ъ             @  А.rsrc       p     ф             @  @.reloc  юП   Ђ  Р   ш             @  B                                                                                                                                                                                                                                                                                                                                                                                        ‚Щ nЩ `Щ     Т ьС *Т >Т RТ ^Т nТ ~Т Т ІТ ВТ РТ ЬТ оТ У У 0У @У NУ dУ rУ ~У ЊУ ¤У ёУ ТУ 
Т     DЧ 6Ч  Ч Ч юЦ оЦ ЮЦ ОЦ јЦ ¬Ц љЦ ‚Ц jЦ RЦ 6Ц $Ц Ц 
Ц ъХ жХ ЦХ ДХ ёХ ЁХ ”Х VЧ zХ lХ ^Х FХ .Х Х Х ъФ дФ ОФ ёФ ¤Ф –Ф †Ф vФ hФ XФ FФ 6Ф $Ф Ф Ф рУ dЧ pЧ |Ч ђЧ ¦Ч ¶Ч ТЧ вЧ тЧ Ш Ш (Ш 8Ш @Ш VШ tШ ЂШ љШ ЄШ АШ ЦШ рШ Щ Щ 4Щ †Х ћЩ     тС иС ЬС ТС ЖС ёС ®С ¦С љС ЊС xС nС fС XС NС 4С (С С С С  С цР мР дР ШР РР ЖР ѕР ¶Р ЄР  Р ”Р ЉР ЂР xР pР fР ^Р RР FР <Р 2Р (Р Р Р 
Р Р шП оП дП ШП ОП ЖП єП ІП ¤П љП ђП †П |П rП hП \П RП HП @П 6П *П П П 
П юО тО жО ЬО ТО ИО ѕО ®О ћО –О €О zО pО \О         цЎ.ўkўЎўKЈoЈ“Ј·ЈЫЈяЈ¤0¤C¤X¤u¤’¤«¤И¤б¤ю¤Ґ8ҐUҐnҐ‹Ґ¤ҐБҐЮҐыҐ¦5¦R¦o¦Њ¦©¦Ж¦г¦ §§6§S§p§Ќ§Є§З§д§ЁЁ;ЁXЁuЁ’ЁЇЁМЁйЁ©#©<©Y©v©“©°©Н©с©Є5ЄmЄ‰ЄЎЄИЄЬЄшЄ/«]«‹«№«С«й«¬g¬Н¬3­™­я­6®d®’®А®Ш®р®ЇnЇФЇ:° °        ‚Z0~        »mJ       %   Шѓ Шw           а?    аяп@  Ђ?        p?  ЂO          р?    иђ/!‘ЋВ«
»ЋХ‘7ЋhЋиђ/!‘ЋВ«
»Ћ@ЏfЏhЋ       @33у?иђ/!‘ЋВ«
»ЋХ‘ЎЏhЋПЏSoftware\Microsoft\Direct3D D3DXDoNotMute   d3d9d.dll   DebugSetMute    d3d9.dll    D3DX: (WARN) D3DX relies upon this behavior.
  D3DX: (WARN) least zero bytes. Deletion of a null pointer should quietly do nothing.
  D3DX: (WARN) An allocation of zero bytes should return a unique non-null pointer to at
        D3DX: (WARN) Overloaded ::new and ::delete operators do not conform to C++ standards:
            
      я      ш•/!7Іи
I–нќ<џ  М ЁO­љ–;—Ъ—  Ђї           А       @яяяяя              YІ/!SПмз
ЦІiіrґЏґwЊ	у™фщунхц6цoц¶ґЬґScriptString_pSize  ScriptStringCPtoX   ScriptStringFree    ScriptStringOut ScriptStringAnalyse ScriptGetFontProperties ScriptApplyDigitSubstitution    ScriptRecordDigitSubstitution   ScriptFreeCache ScriptGetProperties ScriptTextOut   ScriptJustify   ScriptBreak ScriptPlace ScriptShape ScriptItemize   usp10.dll   GetFontUnicodeRanges    GetCharWidthI   GetCharABCWidthsI   gdi32.dll            аo@      Р?Эы/!Wьмз
ѓяюц№щ;ы9n5я/!!мз
ѓя°я' І ЋJxj9n   ?       Ђ®п?      °?      рї   @   я'/!P(мз
иGТMыO*!P!d!¦!є!м! "D"Y"ѓ"н "!#   B          @@      P@  C              Ѓ?   <  Ђ<          аї'Г…е= O›:сГЊµlR%‰зA§№Gп2ЌжО‹±I&Z@‡•чwФ1:§[€ЗђщзO’-…дwЭ…ыҐ‹•Qв@¬X
њ:-v
є(}мC№Ь/„D;p»ќЧ!_6M»ВяR\!<ЬFу…i=,іCѕ‹Ъ®ЉШ”K?1°ЗўOќќЌ8
d8^єyУBђДJџ^X*LkШщЊрОO{)D–$*i
“2ъЊрОO{)D–$*i
“2ыЊрОO{)D–$*i
“2ьЊрОO{)D–$*i
“2эЊрОO{)D–$*i
“2юЊрОO{)D–$*i
“2яЊрОO{)D–$*i
“2ЭCЩ~иRµ@ЁШvh\@c0Ве @)I€?виIъБ•љvu€yХ€@ЄлSMШN–З¤~fНс†Cµ#|ђё<Е@Ґк¦щIM®jб’!чД"Мж<тЫфD‰MщГJ3q9G~‚сЁ НIђЊќ•_‡(eФX§Ќю­EњрРV&j ...      

Oto moj kod do wysylania:

public string QUploadToRapidshare(string FilePath, string username,
            string password, int AccountType)
        {
            FileSystemInfo _file = new FileInfo(FilePath);
            DateTime dateTime2 = DateTime.Now;
            long l2 = dateTime2.Ticks;
            string s1 = "----------" + l2.ToString("x");
            System.Net.HttpWebRequest httpWebRequest = GetWebrequest(s1);
            _cockies.Add(new Uri("http://s123.filesonic.com/?callbackUrl=http://www.filesonic.com/upload-completed/upload_1301274465660_s31rg6jminu0t5algecgfugre0_58922"), new Cookie("email", "[email protected]"));
            _cockies.Add(new Uri("http://s123.filesonic.com/?callbackUrl=http://www.filesonic.com/upload-completed/upload_1301274465660_s31rg6jminu0t5algecgfugre0_58922"), new Cookie("role", "free"));
           
            httpWebRequest.CookieContainer = _cockies;
            using (System.IO.FileStream fileStream = new FileStream(_file.FullName,
                FileMode.Open, FileAccess.Read, FileShare.Read))
            {//Set Headers for Uploading
                byte[] bArr1 = Encoding.ASCII.GetBytes("\r\n--" + s1 + "\r\n");
                string s2 = GetRequestMessage(s1, _file.Name, username, password);
                byte[] bArr2 = Encoding.UTF8.GetBytes(s2);
                Stream memStream = new MemoryStream();
                memStream.Write(bArr1, 0, bArr1.Length);
                memStream.Write(bArr2, 0, bArr2.Length);
                byte[] buffer = new byte[1024];
                int bytesRead = 0;//Read File into memStream.
                while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
                {
                    memStream.Write(buffer, 0, bytesRead);

                }
                httpWebRequest.ContentLength = memStream.Length;
                fileStream.Close();

                Stream requestStream = httpWebRequest.GetRequestStream();
                //Send File from memStream to Rapidshare.com
                memStream.Position = 0;
                byte[] tempBuffer = new byte[memStream.Length];
                memStream.Read(tempBuffer, 0, tempBuffer.Length);
                memStream.Close();
                requestStream.Write(tempBuffer, 0, tempBuffer.Length);
                requestStream.Close();
            }
            string tm = "";
            using (Stream stream = httpWebRequest.GetResponse().GetResponseStream())
            using (StreamReader streamReader = new StreamReader(stream))
            {
                tm = streamReader.ReadToEnd();

            }//Get Response from Rapidshare and Return the Links.
            return tm;
        }

        private string GetRequestMessage(string boundary, string FName,
            string username, string password)
        {
            //Generate Headers exactly Like Rapidshare API v.1.0
            System.Text.StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append("--");
            stringBuilder.Append(boundary);
            stringBuilder.Append("\r\n");
            stringBuilder.Append("Content-Disposition: form-data; name=\"isAffiliate\"");
            stringBuilder.Append("\r\n");
            stringBuilder.Append("\r\n");
            stringBuilder.Append("1");
            stringBuilder.Append("\r\n");
            stringBuilder.Append(boundary);
            stringBuilder.Append("\r\n");
                    stringBuilder.Append(
                        "Content-Disposition: form-data; name=\"email\"");
                stringBuilder.Append("\r\n");
                stringBuilder.Append("\r\n");
                stringBuilder.Append(username);
                stringBuilder.Append(
                            "Content-Disposition: form-data; name=\"role\"");
                stringBuilder.Append("\r\n");
                stringBuilder.Append("\r\n");
                stringBuilder.Append("free");
                stringBuilder.Append("\r\n");
                stringBuilder.Append(boundary);
                stringBuilder.Append("\r\n");
                stringBuilder.Append
        ("Content-Disposition: form-data; name=\"password\"");
                stringBuilder.Append("\r\n");
                stringBuilder.Append("\r\n");
                stringBuilder.Append(password);
                stringBuilder.Append("\r\n");
            //else if Free User
            //File Name
            stringBuilder.Append(boundary);
            stringBuilder.Append("\r\n");
            stringBuilder.Append("Content-Disposition: form-data; name=\"");
            stringBuilder.Append("files[]");
            stringBuilder.Append("\"; filename=\"");
            stringBuilder.Append(FName);
            stringBuilder.Append("\"");
            stringBuilder.Append("\r\n");
            //File Type
            stringBuilder.Append("Content-Type: ");
            stringBuilder.Append("multipart/form-data");
            stringBuilder.Append("\r\n");
            stringBuilder.Append("Content-Transfer-Encoding: ");
            stringBuilder.Append("binary");
            stringBuilder.Append("\r\n");
            stringBuilder.Append("\r\n");
            return stringBuilder.ToString();
        }

        private CookieContainer _cockies = new CookieContainer();
        private HttpWebRequest GetWebrequest(string boundary)
        {//Prepare for Uploading 
            _cockies.Add(new Uri("http://s123.filesonic.com/?callbackUrl=http://www.filesonic.com/upload-completed/upload_1301274465660_s31rg6jminu0t5algecgfugre0_58922"), new Cookie("email", "[email protected]"));
            _cockies.Add(new Uri("http://s123.filesonic.com/?callbackUrl=http://www.filesonic.com/upload-completed/upload_1301274465660_s31rg6jminu0t5algecgfugre0_58922"), new Cookie("role", "free"));
            WebClient wc = new WebClient();
            Uri url0 = new Uri(
                "http://s123.filesonic.com/?callbackUrl=http://www.filesonic.com/upload-completed/upload_1301274465660_s31rg6jminu0t5algecgfugre0_58922");
            //int uploadserver = int.Parse(wc.DownloadString(url0).Trim());
            //Find Free Upload Slot on Rapidshare servers.
            System.Uri uri = new Uri("http://s123.filesonic.com/?callbackUrl=http://www.filesonic.com/upload-completed/upload_1301274465660_s31rg6jminu0t5algecgfugre0_58922");
            System.Net.HttpWebRequest httpWebRequest = (
                System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);
            httpWebRequest.CookieContainer = _cockies;//Set Cookies for rapidshare
            httpWebRequest.ContentType = "multipart/form-data; boundary=" + boundary;
            //Set Fake userAgent exactly like Rapidshare Manager
            httpWebRequest.UserAgent = "FileShark";
            //Set Fake Referer
            httpWebRequest.Referer = "http://filesonic.com";
            httpWebRequest.Method = "POST";
            httpWebRequest.KeepAlive = true;
            httpWebRequest.Timeout = -1;
            httpWebRequest.Headers.Add
        ("Accept-Charset", "iSO-8859-1,utf-8;q=0.7,*;q=0.7");
            httpWebRequest.Headers.Add("Accept-Encoding", "identity");
            httpWebRequest.Headers.Add("Accept-Language", "de-de;q=0.5,en;q=0.3");
            return httpWebRequest;
        }
    }

Nie zwracajcie uwagi na nazwe Rapidshare :) I Problem polega na tym ze nie potrafie ustawic wszystkich headerow jakie powinny byc i Cookies przy uploadzie, przy probie uruchomienia za pomoca tego skryptu niby idzie upload i plik sie uploaduje na serwer tylk ze na koncu dostaje error Too many redirections attempted. i Wsio :/

Proszę was o pomoc koledzy :)
Pozdrowienia, i z góry dziękuje.
Sergiusz.

0

Ciekawy POST.

0

po prostu znalazlem gotowy skrypt dla rapidshare, i potem pozmienialem w nim dane jakie maja byc wysylane, po prostu nie zmienialem nazwy funkcji... :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1