2014-04-06 38 views
0

我想上傳文件上傳文件oboom.com我登錄成功,但是當嘗試後的文件我得到這個錯誤錯誤500無法用Delphi印

HTTP/1.1500內部服務器錯誤。

與此respose文字

[500,"illegal post header","Content-Transfer-Encoding"]

procedure TForm1.Button1Click(Sender: TObject); 
var 
    S: tstringlist; 
    html: string; 
    clHttpRequest1: tclHttpRequest; 
    SSLIOHandlerSocketOpenSSL: TIdSSLIOHandlerSocketOpenSSL; 
    params: TIdMultiPartFormDataStream; 
    HTTP, HTTP2: tidhttp; 
begin 
    params := TIdMultiPartFormDataStream.Create; 
    S := tstringlist.Create; 
    HTTP2 := tidhttp.Create(nil); 
    try 
    cookie := tidcookiemanager.Create(nil); 
    SSLIOHandlerSocketOpenSSL := TIdSSLIOHandlerSocketOpenSSL.Create(nil); 
    HTTP2.IOHandler := SSLIOHandlerSocketOpenSSL; 
    HTTP2.HandleRedirects := False; 
    HTTP2.ConnectTimeout := 10000; 
    HTTP2.ReadTimeout := 10000; 
    HTTP2.CookieManager := cookie; 
    HTTP2.AllowCookies := True; 
    HTTP2.Request.UserAgent := 
     'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36'; 
    HTTP2.Request.ContentType := 'application/x-www-form-urlencoded'; 
    HTTP2.Request.ContentEncoding := 'gzip, deflate'; 
    HTTP2.Request.Accept := '*/*'; 
    HTTP2.Request.Connection := 'Keep-Alive'; 
    S.Values['auth'] := '[email protected]'; 
    S.Values['pass'] := 'password'; 
    S.Values['app_id'] := '5hwaJUcDicXprlV3gjaB'; 
    S.Values['app_session'] := '288196272'; 
    html := HTTP2.Post('https://www.oboom.com/1.0/login', S); 
    finally 
    HTTP2.Free; 
    S.Free; 
    end; 
    token := ExtractBetween(html, 'session":"', '"'); 
    try 
    HTTP := tidhttp.Create; 
    HTTP.HandleRedirects := True; 
    HTTP.Request.Connection := 'keep-alive'; 
    HTTP.AllowCookies := True; 
    HTTP.CookieManager := cookie; 
    HTTP.Request.Referer := 'http://upload.oboom.com'; 
    HTTP.Request.ContentType := 
     'multipart/form-data; boundary=----------GI3Ef1cH2GI3gL6ae0Ef1KM7Ef1gL6'; 
    HTTP.Request.Accept := '*/*'; 
    HTTP.Request.AcceptEncoding := 'gzip,deflate'; 
    HTTP.ConnectTimeout := 20000; 
    HTTP.ReadTimeout := 20000; 
    HTTP.Request.UserAgent := 
     'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36'; 
    params.AddFile('file', 'C:\Users\M\Pictures\Martin.jpg',); 
    HTTP.Post('http://upload.oboom.com/1.0/ul?token=' + token + 
     '&parent=1&name_policy=rename', params); 
    finally 
    HTTP.Free; 
    params.Free; 
    cookie.Free; 
    end; 
    memo1.Text := html; 
end; 

我用Google搜索小時一個解決方案,但沒有運氣:/

試過這樣:

Params.AddFile('file', 'C:\Users\M\Pictures\Martin.jpg','application/octet-stream'); 
Params.AddFile('file', 'C:\Users\M\Pictures\Martin.jpg','multipart/form-data'); 

但是s AME錯誤

我試圖巧妙互聯網compenent併成功上傳文件,但我想印用..

我用delphi X3

回答

2

你需要擺脫這些行:

HTTP2.Request.ContentEncoding := 'gzip, deflate'; 

HTTP.Request.AcceptEncoding := 'gzip,deflate'; 

TIdHTTP管理ŧ軟管值取決於其Compressor屬性是否已分配和啓用。而且,您並未發送壓縮請求,因此不應使用這些值。

此外,您還需要擺脫這一行:

HTTP.Request.ContentType := 
    'multipart/form-data; boundary=----------GI3Ef1cH2GI3gL6ae0Ef1KM7Ef1gL6'; 

Post()爲您管理的是價值,特別是boundary,其中TIdMultipartFormDtaStream動態生成。

更新Content-Transfer-Encoding的唯一其他地方是在TIdMultipartFormDataStream的個別字段。每個TIdFormDataField具有ContentTransfer屬性。 AddFile()初始化爲'binary',但你也可以將其設置爲空字符串以禁用標題:

params.AddFile(...).ContentTransfer := ''; 
+0

我還在歌廳同樣的錯誤:( – Helios

+0

我更新了我的答案 –

+0

工作就像它應該,謝謝。您 – Helios