Post request
-
Hallo, ich spiel gerade etwas mit meinem Xampp Server rum.
Die Datei dich ich holaden will liegt in einem Order auf dem Desktop aber in dem HTPP request sehe ich nichts von einer Pfad angabe.
Kann es sein das man mit dieser Methode gar keinen Dateiupload über ein HTML Formular machen kann?
In dem request sehe ich nur den Dateinamen aber der Pfad wird nicht mit angegeben
Request den ich mit Live HTPP Headers ausglesen habe. (Firefox Plugin)
POST /FileUpload/FileUpload.php HTTP/1.1 Host: 127.0.0.1 User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20100101 Firefox/14.0.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3 Accept-Encoding: gzip, deflate Connection: keep-alive Referer: http://127.0.0.1/FileUpload/FileUpload.html Content-Type: multipart/form-data; boundary=---------------------------27212317658206 Content-Length: 288593 -----------------------------27212317658206 Content-Disposition: form-data; name="MAX_FILE_SIZE" 99999999999999999999 -----------------------------27212317658206 Content-Disposition: form-data; name="uploadedfile"; filename="Project2.bin" Content-Type: application/octet-stream MZP
Hier meine Webserver Dateien:
FileUpload.html
<form enctype="multipart/form-data" action="FileUpload.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="99999999999999999999" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form>
FileUpload.php
<?php /*/ Dateiendungsfilter fehlt noch .. /*/ $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "There was an error uploading the file, please try again!"; } ?>
-
Warum sollte auf dem Server ein Pfad zu Deiner lokalen Datei drin stehen... der kann damit nix anfangen...
-
Ja, stimmt die Daten der Datei werden anscheind direkt dem request übergeben.
Ich habs jetzt mal mit einer Textdatei versucht:
So sieht mein POST request string aus:
string filename = "\x22" "datei.txt" "\x22"; string filesize = "\x22" "MAX_FILE_SIZE" "\x22"; string request = "POST /FileUpload/FileUpload.php HTTP/1.1\r\n" "Host: 127.0.0.1\r\n" "User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20100101 Firefox/14.0.1\r\n" "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3\r\n" "Accept-Encoding: gzip, deflate\r\n" "Connection: keep-alive\r\n" "Referer: http://127.0.0.1/FileUpload/FileUpload.html\r\n" "Content-Type: multipart/form-data; boundary=---------------------------230312598217877\r\n" "Content-Length: 328\r\n" " -----------------------------230312598217877\r\n" " Content-Disposition: form-data; name="; request += filesize += "\r\n"; request+="\r\n"; request+=" 99999999999999999999\r\n"; request+=" -----------------------------230312598217877\r\n"; request+=" Content-Disposition: form-data; name='uploadedfile'; filename="; request+= filename += "\r\n"; request+=" Content-Type: text/plain\r\n"; request+="\r\n"; request+=" abcde\r\n"; request+=" -----------------------------230312598217877--\r\n"; request+="\r\n\r\n";
Als Rückgabe bekomme ich immer:
HTTP/1.1 413 Request Entity Too Large Date: Tue, 31 Jul 2012 10:33:52 GMT Server: Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_ color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1 Vary: accept-language,accept-charset Accept-Ranges: bytes Connection: close Content-Type: text/html; charset=iso-8859-1 Content-Language: de
Was ist da falsch an dem request?
-
Stimmt die "Content-Length"!?
-
Ja, die content Länge ist richtig.
-
Den Fehler mit dem: HTTP/1.1 413 Request Entity Too Large
konnte ich beheben ich hatte eine Leerstelle falsch ...Jetzt gibt mir mein Server auch ein OK zurück
HTTP/1.1 200 OK Date: Wed, 01 Aug 2012 10:29:35 GMT Server: Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_ color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1 X-Powered-By: PHP/5.3.1 Content-Length: 58 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive Content-Type: text/html
Aber die Datei wird trotzdem nicht hochgeladen.
Hier sind alle Sachen die ich benutze:
index.html
<form enctype="multipart/form-data" action="FileUpload.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="1000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form>
FileUpload.php
<?php echo $uploadedfile; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "There was an error uploading the file, please try again!"; } ?>
Uploader
#include <iostream> #include <windows> #include <vector> using namespace std; int main() { char *request = "POST /FileUpload.php HTTP/1.1\r\n" "Host: 127.0.0.1\r\n" "User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20100101 Firefox/14.0.1\r\n" "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3\r\n" "Accept-Encoding: gzip, deflate\r\n" "Connection: keep-alive\r\n" "Referer: http://127.0.0.1/\r\n" " Content-Type: multipart/form-data; boundary=---------------------------4827543632391\r\n" " Content-Length: 299\r\n" " -----------------------------4827543632391\r\n" " Content-Disposition: form-data; name=\"MAX_FILE_SIZE\"\r\n" "\r\n" " 10\r\n" " -----------------------------4827543632391\r\n" " Content-Disposition: form-data; name=\"uploadedfile\"; filename=\"datei.txt\"\r\n" " Content-Type: text/plain\r\n" "\r\n" "\r\n" "-----------------------------4827543632391--\r\n" "\r\n" "\r\n"; WSAData wsadata; WORD wsver=MAKEWORD( 2 , 2 ); int nret = WSAStartup(wsver, &wsadata); if ( nret != 0 ) { cout<<"Startup error: "<< GetLastError()<<endl; system("PAUSE"); return 0; } SOCKET clientSocket = socket(AF_INET, SOCK_STREAM, 0); if ( clientSocket == INVALID_SOCKET) { cout<<"Create error: "<< GetLastError()<<endl; system("PAUSE"); return 0; } sockaddr_in sin; sin.sin_port=htons( 80 ); sin.sin_addr.s_addr=inet_addr( "127.0.0.1"); sin.sin_family=AF_INET; long rc = connect(clientSocket,(sockaddr*)&sin, sizeof(sin)); rc = send(clientSocket, request, strlen(request), 0); if(rc==0) { cout<<"send error"<< GetLastError()<<endl; system("PAUSE"); return 0; } vector<char>RecvData(500); rc = recv( clientSocket, &RecvData[0] , 500 ,0); cout<<&RecvData[0]<<endl; system("PAUSE"); }
Falls wer eine Idee hat würde ich mich freuen ...
-
So nachdem ich mit den Firefox Plugins nicht zum Ziel gekommen bin hab ich es mal mit Wireshark versucht jetzt funktioniert es endlich.
Nachher kommen dann die Binär Dateien ... was mich da wohl erwartet.^^
char* request= "POST /FileUpload.php HTTP/1.1\r\n" "User-Agent: Opera/9.80 (Windows NT 5.1; U; de) Presto/2.10.289 Version/12.00\r\n" "Host: 127.0.0.1\r\n" "Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1\r\n" "Accept-Language: de-DE,de;q=0.9,en;q=0.8\r\n" "Accept-Encoding: gzip, deflate\r\n" "Referer: 127.0.0.1\r\n" "Connection: Keep-Alive\r\n" "Content-Length: 280\r\n" "Content-Type: multipart/form-data; boundary=----------rKHwFXmjXQZtaW1K3BtfmI\r\n" "\r\n" "------------rKHwFXmjXQZtaW1K3BtfmI\r\n" "Content-Disposition: form-data; name=\"MAX_FILE_SIZE\"\r\n" "\r\n" "1000\r\n" "------------rKHwFXmjXQZtaW1K3BtfmI\r\n" "Content-Disposition: form-data; name=\"uploadedfile\"; filename=\"datei.txt\"\r\n" "Content-Type: text/plain\r\n" "\r\n" "abc\r\n" "------------rKHwFXmjXQZtaW1K3BtfmI--\r\n";