idhttp訪問DATASNAP有密碼驗證的中間件
用TIDHttp訪問DataSnap Rest服務器,在服務器采用了用戶驗證的情況下,客戶端需要提交密碼,否則不能正常連接。
procedure TForm15.Button2Click(Sender: TObject); var url, params, Text: string; code: Integer; http: TIDHttp; begin http:= TIDHttp.Create(nil); http.Request.BasicAuthentication := True; http.request.password := '密碼'; // 提交密碼 params := Edit1.Text; url:= 'http://192.168.10.182:8081/datasnap/rest/TSM/EchoString/'; try text := http.Get(URL+TIdURI.ParamsEnCode(params)); Edit2.Text := Text; except on E: Exception do begin end; end; end;