请告知Delphi XE中是否有WinHTTP包装器
按优先顺序排列:
解决方案:
由于评论不允许格式化代码,我在问题中粘贴解决方案:
const
winhttpdll = 'winhttp.dll';
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY = 0;
WINHTTP_FLAG_REFRESH = $00000100;
WINHTTP_FLAG_SECURE = $00800000;
WINHTTP_ADDREQ_FLAG_COALESCE = $40000000;
WINHTTP_QUERY_FLAG_NUMBER = $20000000;
function WinHttpOpen(pwszUserAgent: PWideChar; dwAccessType: DWORD;
pwszProxyName, pwszProxyBypass: PWideChar; dwFlags: DWORD): HINTERNET; stdcall; external winhttpdll;
function WinHttpConnect(hSession: HINTERNET; pswzServerName: PWideChar;
nServerPort: INTERNET_PORT; dwReserved: DWORD): HINTERNET; stdcall; external winhttpdll;
function WinHttpOpenRequest(hConnect: HINTERNET; pwszVerb: PWideChar;
pwszObjectName: PWideChar; pwszVersion: PWideChar; pwszReferer: PWideChar;
ppwszAcceptTypes: PLPWSTR; dwFlags: DWORD): HINTERNET; stdcall; external winhttpdll;
function WinHttpCloseHandle(hInternet: HINTERNET): BOOL; stdcall; external winhttpdll;
function WinHttpAddRequestHeaders(hRequest: HINTERNET; pwszHeaders: PWideChar; dwHeadersLength: DWORD;
dwModifiers: DWORD): BOOL; stdcall; external winhttpdll;
function WinHttpSendRequest(hRequest: HINTERNET; pwszHeaders: PWideChar;
dwHeadersLength: DWORD; lpOptional: Pointer; dwOptionalLength: DWORD; dwTotalLength: DWORD;
dwContext: DWORD): BOOL; stdcall; external winhttpdll;
function WinHttpReceiveResponse(hRequest: HINTERNET;
lpReserved: Pointer): BOOL; stdcall; external winhttpdll;
function WinHttpQueryHeaders(hRequest: HINTERNET; dwInfoLevel: DWORD; pwszName: PWideChar;
lpBuffer: Pointer; var lpdwBufferLength, lpdwIndex: DWORD): BOOL; stdcall; external winhttpdll;
function WinHttpReadData(hRequest: HINTERNET; lpBuffer: Pointer;
dwNumberOfBytesToRead: DWORD; var lpdwNumberOfBytesRead: DWORD): BOOL; stdcall; external winhttpdll;
function WinHttpQueryDataAvailable(hRequest: HINTERNET; var lpdwNumberOfBytesAvailable: DWORD): BOOL;
stdcall; external winhttpdll;
function WinHttpSetOption(hInternet: HINTERNET; dwOption: DWORD; lpBuffer: Pointer; dwBufferLength: DWORD): BOOL;
stdcall; external winhttpdll;
function WinHttpQueryOption(hInternet: HINTERNET; dwOption: DWORD; var lpBuffer: Pointer; var lpdwBufferLength: DWORD): BOOL;
stdcall; external winhttpdll;
function WinHttpWriteData(hRequest: HINTERNET; lpBuffer: Pointer; dwNumberOfBytesToWrite: DWORD;
var lpdwNumberOfBytesWritten: DWORD): BOOL; stdcall; external winhttpdll;
function WinHttpCheckPlatform(): BOOL; stdcall; external winhttpdll;
还有一些失踪者:
WinHttpCrackUrl
WinHttpCreateUrl
WinHttpSetStatusCallback
WinHttpTimeFromSystemTime
WinHttpTimeToSystemTime
答案 0 :(得分:11)
如果要在应用程序中实现HTTP客户端访问,可以考虑以下几种选择:
对于our ORM,对于其HTTP / 1.1连接层,我们尝试避免外部依赖,并且不需要所有Indy的功能和开销。
我们首先编写了自己的WinSock包装器,然后尝试了WinInet。在我们的测试基准测试中使用时,我们发现WinINet死得很慢。
然后我们尝试了微软提供的新API WinHTTP,我们发现这个速度非常快。与直接WinSock访问一样快,无需编写所有包装代码。
所以这是我们的OpenSource WinHTTP包装器,在unit named SynCrtSock中。从Delphi 5到XE测试。
你会看到我们为WinINet和WinHTTP使用了相同的泛型类。事实上,两个图书馆都非常接近。
见this article for details。有关于自动代理检索的说明。
使用即将推出的Delphi XE2编辑:,您将能够交叉编译到Mac OS X.在这种情况下,使用“抽象”类完全有意义,例如{ {1}}。在Windows下,它将使用WinHTTP,但在Mac OS X下,它将调用套接字API。要编译代码,您只需调整类类型,而不是代码。
答案 1 :(得分:6)
C:\Windows\system32\winhttp.dll
然后使用它:
var
http: IWinHttpRequest;
szUrl: WideString;
begin
szUrl := 'http://stackoverflow.com/questions/6725348/winhttp-delphi-wrapper';
http := CoWinHttpRequest.Create;
http.open('GET', szUrl, False);
http.send(EmptyParam);
if (http.status = 200) then
ShowMessage(http.responseText);
所以: