我正在从Delphi 2005升级到Delphi 2010.我遇到了这个问题:以下程序在D2005上运行良好但在D2010上我总是得到结果:
<HTML><HEAD><TITLE>401 Unauthorized</TITLE></HEAD>
<BODY><H1>401 Unauthorized</H1>
Your client does not have permission to get URL /axis-cgi/date.cgi from this server.
</BODY></HTML>
Run Code Online (Sandbox Code Playgroud)
在程序上,我尝试连接两次因为在D2005,有时我在第一次尝试时得到了一个未经授权的答案,然后我可以第二次连接没有问题.使用D2010,我总是得到未经授权的回答.
Url ='http:// user:pass@xxx.xxx.xxx.xxx/axis-cgi/date.cgi?action = get'
function TViewCameraForm.HttpGet(idHTTP : TidHTTP; Url : AnsiString): AnsiString;
Var
Res : AnsiString;
Begin
idHTTP1.Disconnect;
try
Res := idHTTP1.Get(Url);
If Pos('Unauthorized', Res) > 0 Then
Res := idHTTP1.Get(Url);
Result := Res;
except
on E: EIdHTTPProtocolException do begin
Result := E.ErrorMessage
end;
on E: Exception do begin
Result := E.message;
end;
end;
End;
Run Code Online (Sandbox Code Playgroud)
谢谢山姆
目标:从网站(普通主机)下载档案.用户必须对网站上的下载,连接和文件存储一无所知.
我使用idHTTP + SSL下载档案.但是用户可以访问网站 - >我可以设置基本身份验证,但用户可以在HTTP Analyzer中看到用户名/密码.
程序下载带有设置的文件.设置采用纯文本形式.此文本也可以在HTTP Analyzer中看到.
我可以加密这个文本,但档案呢?我需要一次保护所有东西.
因此,我不希望用户看到档案和设置文件的网址.它可以粘贴在网络浏览器中 - >请下载所有内容......
如何防止这些?
谢谢!!!!!!!!
我有Delphi XE.我尝试设置Request.Range,idHttp但我不能这样做.Delphi不允许我在设计时和运行时都这样做.
例如,我设置'6000-'了一个设计时间 - >一个属性一直空着.
我做(在线程中):
Downloader.Request.Range:=(IntToStr(DFileStream.Position) + '-');
synchronize(procedure begin showmessage(Downloader.Request.Range) end);
Run Code Online (Sandbox Code Playgroud)
showmessage(Downloader.Request.Range) 没有给我看(一个空字符串).
我在HTTPAnalyzer中检查了一个请求 - >我的程序没有发送范围.
在Delphi 2010中检查了这种行为 - 一切正常.我在设计/实时设置范围.在这两种情况下结果都很好.
有人有想法吗?
这是一个错误还是什么?
谢谢!
我正在尝试使用Indy 10中的GET方法,但我的URL长度大于255个字符.并且GET方法只接受"字符串"参数.
body := httpCom.Get('..........wide string.........')
Run Code Online (Sandbox Code Playgroud)
Delphi的编译器给我错误:
"字符串文字最多可包含255个元素"
是否有任何解决方案或不同的第三方组件来解决这个问题?
我在表单上有一个TIdHTTP组件,并且正在向基于云的服务器发送http POST请求。除1个字段外,其他所有东西都运行良好:带有加号的文本字符串(例如“ hello world + dog”)被保存为“ hello world dog”。
研究此问题后,我意识到URL中的“ +”被视为空格,因此必须对其进行编码。这就是我感到难过的地方;看起来除“ +”外,其余POST请求均由TIdHTTP组件编码。
通过Fiddler查看请求,它以“ hello%20world + dog”的形式出现。如果我手动编码“ +”(hello world%2Bdog),则结果为“ hello%20world%252Bdog”。
我真的不知道我在这里做什么,所以如果有人可以向我指出正确的方向,将不胜感激。
其他信息:
我正在使用Delphi2010。该组件没有任何特殊设置,我想可能需要设置一些内容?Fiddler中出现的标头内容类型为“ application / x-www-form-urlencoded”。
然后,Delphi代码:
Request:='hello world+dog';
URL :='http://............./ExecuteWithErrors';
TSL:=TStringList.Create;
TSL.Add('query='+Request);
Try
begin
IdHTTP1.ConnectTimeout:=5000;
IdHTTP1.ReadTimeout :=5000;
Reply:=IdHTTP1.Post(URL,TSL);
Run Code Online (Sandbox Code Playgroud) 使用TIdHTTPServer(Indy 10.6),我想为关闭慢速或非活动客户端(客户端是常见浏览器)设置连接超时,并在60秒不活动后关闭所有僵尸连接.我在TIdContext.Connection中找到了Socket.ReadTimeout.这是正确的方法吗?TIdHTTPServer已经执行了这个(看起来有无限超时)?
WebServer := TIdHTTPServer.Create(nil);
WebServer.SessionState := false;
WebServer.KeepAlive := false;
WebServer.OnCommandGet := CustomOnCommandGet;
procedure CustomOnCommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo;
begin
AContext.Connection.Socket.ReadTimeout := 60000;
AResponseInfo.ContentStream := TFileStream.Create('C:/file.zip', fmOpenRead or fmShareCompat);
end;
Run Code Online (Sandbox Code Playgroud) 如何使用以下IdHTTP方式发送消息PostMan:
我的第一次尝试如下:
function TIdFoo.SendIM(const AID, AMessage: string): Boolean;
const
_URL = 'https://URL.com/SendMessage';
var
Params : TStringStream;
Response : string;
LMsg : string;
begin
Result := False;
LMsg := '-----------------------------13932'+
'Content-Type: application/json; charset=utf-8'+
'Content-Description: message'+ sLineBreak+ '{"message":{"Type":1,"body":"'+AMessage+'"},"to":["'+AID+'"]}'+
'-----------------------------13932--;'+sLineBreak;
Params := TStringStream.Create(LMsg, TEncoding.UTF8);
try
IdHTTP.Request.CustomHeaders.AddValue('authorization', 'Bearer ' + FToken);
IdHTTP.Request.CustomHeaders.AddValue('Origin', 'https://www.URL.com');
IdHTTP.Request.UserAgent := 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.104 Safari/537.36';
IdHTTP.Request.Accept := '*/*';
IdHTTP.Request.Referer := 'https://www.URL.com/en-us/';
IdHTTP.Request.Host := 'URL.com';
IdHTTP.Request.AcceptEncoding := 'gzip, deflate, br';
IdHTTP.Request.AcceptLanguage …Run Code Online (Sandbox Code Playgroud) 我想获取我使用 Delphi 以 HTML 格式发送的 post 值。我正在使用TIdHTTPServer.
我的目标是获取POST发送的数据。但有一个问题。我使用如下图所示的工具将其作为“表单数据”发送。捕获 POST 请求。
不幸的是,当我发出与HTML相同的请求时,它看不到 POST。我如何实现这一目标?
procedure TForm1.serviceCommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
receiveStream: TStream;
begin
if ARequestInfo.URI = '/test.php' then
begin
if ARequestInfo.Command = 'POST' then
begin
receiveStream := ARequestInfo.PostStream;
if Assigned(receiveStream) then
begin
LOG.Lines.Add(ReadStringFromStream(receiveStream));
end;
AResponseInfo.ResponseNo := 200;
end;
end;
end;
Run Code Online (Sandbox Code Playgroud)
HTML POST 请求(Delphi 没有看到那个请求。我的目标是实现这个愿望。)
<form method="post" action="http://localhost:99/test.php">
<input type="hidden" name="test" value="04545">
<input type="submit" value="send"/>
</form>
Run Code Online (Sandbox Code Playgroud) 我必须在我们的应用程序中创建一个嵌入式 HTTP 服务器。这个必须是为进程间通信创建的,因为对方只能调用WebService。
我们不需要一次处理更多请求,但我必须使用来自主线程的库和数据库连接。
Delphi版本是Seattle,Indy版本是10(内部)。
据我所知,IdHTTPServer 使用线程进行连接 - 和以前一样。但是新的事件处理程序不直接传递 Thread - 所以我不能像 N 年前那样调用 TThread.Synchronize。而且我没有找到任何获取线程的方法。
我在某处读到 TIdSync 或 TIdNotify 类可以帮助我。我找不到任何完整的例子来了解如何。
看到这个简单的代码。在主线程中完成我的工作就足够了吗?
procedure TForm5.IdHTTPServer1CommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo;
AResponseInfo: TIdHTTPResponseInfo);
begin
FURI := ARequestInfo.URI; // Store the URI for main thread access
FResult := '';
TIdSync.SynchronizeMethod(Self.ProcessIt); // Call sync to process in VCL thread
AResponseInfo.ContentText := FResult; // This variable contains the result
end;
Run Code Online (Sandbox Code Playgroud)
还是我做错了什么?
感谢您的帮助!
日
我有这个从网络获取图像网址的线程然后将其保存到内存流然后从内存流保存到文件
我需要转换下载到gif图像的任何图像,所以我做这样的事情
unit downloadimgThread;
interface
uses Windows, SysUtils, Classes, dialogs, IdSSLOpenSSL, IdHttp, IdUri, System.AnsiStrings, Graphics, Jpeg, Vcl.Imaging.GIFImg, PNGImage;
type
TDownloadUpdateVisualEvent = procedure(Sender: TObject; Anameofimg: String;
var Aimagelocate: String) of object;
type
TURLDownload = class(TThread)
private
FOnUpdateVisual: TDownloadUpdateVisualEvent;
FURL: String;
Fnameofimg: string;
FPathImage: string;
FFileNameImage: string;
ImageName: string;
PathURL: string;
procedure DoUpdateVisual;
protected
procedure Execute; override;
public
constructor Create(Thrdid: Pointer; const AUrl: String;
Const AOutPathImages: string; AOnUpdateVisual: TDownloadUpdateVisualEvent;
Anameofimg: String); reintroduce;
property URL: string read FURL write FURL;
property PathImage: string …Run Code Online (Sandbox Code Playgroud) delphi ×10
idhttp ×10
indy ×4
http ×3
delphi-2010 ×2
http-post ×2
indy10 ×2
delphi-xe ×1
delphi-xe8 ×1
encryption ×1
rad-studio ×1
range ×1
security ×1
string ×1
vcl ×1