XE5 的 IdHTTPServer 元件使用上有問題 |
尚未結案
|
Arnor
一般會員 發表:28 回覆:29 積分:16 註冊:2006-10-28 發送簡訊給我 |
這是承之前無法用USB讀取APP 內所建立檔案的問題, 我所想用的解決方法,
理論上蠻好, 但舊問題沒解, 新問題又來....XE5 真的很讓人只可遠觀不可褻玩焉. 方法是在 APP 裡直接放個 HTTP SERVER 提供其它電腦做 web browsing 查看檔案列表並下載. 程式碼節錄如下: procedure TTabbedForm.Button3Click(Sender: TObject); begin try IdHTTPSrrver1.Active := true; if IdHttpserver1.Active then showmessage('http server started'); except on E:Exception do begin showmessage(E.Message); end; end; end; procedure TTabbedForm.IdHTTPServer1CommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo); var SR : TsearchRec; tmpPage, filename : string; ByteSent : integer; begin CurDir := TPath.GetHomePath PathDelim; //showmessage('CurDir=' CurDir); <- 直接控制 UI 不是 thread safe 作法, 故 mark 起來 //showmessage('ARequestInfo.Document=' ARequestInfo.Document); if ((lowercase(ARequestInfo.Document) = '') or (lowercase(ARequestInfo.Document) = '/')) then begin tmpPage := '<html>' #13#10; tmpPage := tmpPage '<body>' #13#10; if FindFirst(CurDir '*.*', faAnyFile, SR) = 0 then try repeat if (sr.Attr and faDirectory) <> faDirectory then begin try tmpPage := tmpPage '' SR.Name ' ' #13#10; except end; end; until (FindNext(SR) <> 0); finally FindClose(SR); end; tmpPage := tmpPage '</body>' #13#10; tmpPage := tmpPage '</html>' #13#10; AResponseInfo.ContentType := 'text/html'; AResponseInfo.ContentText := tmpPage; end else if lowercase(Copy(lowercase(ARequestInfo.Document),1,11)) = '/downloads/' then begin filename := Copy(ARequestInfo.Document, 12, length(ARequestInfo.Document) - 11); AResponseInfo.ContentType := GetMIMETypeFromFile(filename); AResponseInfo.ContentDisposition := 'attachment; filename="' filename '";'; ByteSent := AResponseInfo.ServeFile(AContext, CurDir filename); end; 以上程式碼 win32 可行, 到 android 就不行, 更正確的錯誤應該是連 commandget 都沒有被呼叫到.... 請問有人可以指導在 APP 上放置 HTTP SERVER 可運作的方式嗎? 編輯記錄
Arnor 重新編輯於 2014-01-28 13:17:45, 註解 無‧
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |