博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Delphi UniDAC 通过http协议连接数据库的设置
阅读量:4364 次
发布时间:2019-06-07

本文共 3119 字,大约阅读时间需要 10 分钟。

Connection through HTTP tunnel(using http protocol)

Sometimes client machines are shielded by a firewall that does not allow you to connect to server directly at the specified port. If the firewall allows HTTP connections, you can use UniDAC together with HTTP tunneling software to connect to MySQL server.

UniDAC supports HTTP tunneling based on the PHP script.

An example of the web script tunneling usage can be the following: you have a remote website, and access to its database through the port of the database server is forbidden. Only access through HTTP port 80 is allowed, and you need to access the database from a remote computer, like when using usual direct connection.

You need to deploy the tunnel.php script, which is included into the provider package on the web server. It allows access to the database server to use HTTP tunneling. The script must be available through the HTTP protocol. You can verify if it is accessible with a web browser. The script can be found in the HTTP subfolder of the installed provider folder, e. g. %Program Files%\Devart\UniDac for Delphi X\HTTP\tunnel.php. The only requirement to the server is PHP 5 support.

To connect to the database, you should set TUniConnection parameters for usual direct connection, which will be established from the web server side, the Protocol specific MySQL option to mpHttp, and set the following parameters, specific for the HTTP tunneling:

Specific Option Mandatory Meaning
HttpUrl Yes Url of the tunneling PHP script. For example, if the script is in the server root, the url can be the following: http://localhost/tunnel.php.
HttpUsername, HttpPassword No Set this properties if the access to the website folder with the script is available only for registered users authenticated with user name and password.

Connection through proxy and HTTP tunnel

Consider the previous case with one more complication.

HTTP tunneling server is not directly accessible from client machine. For example, client address is 10.0.0.2, server address is 192.168.0.10, and the MySQL server listens on port 3307. The client and server reside in different networks, so the client can reach it only through proxy at address 10.0.0.1, which listens on port 808. In this case in addition to the Http specific options you have to setup the Proxy specific options as follows:

UniConnection := TUniConnection.Create(self);UniConnection.ProviderName := 'MySQL';UniConnection.Server := '192.168.0.10';UniConnection.Port := 3307;UniConnection.Username := 'root';UniConnection.Password := 'root';UniConnection.SpecificOptions.Values['Protocol'] := 'mpHttp';UniConnection.SpecificOptions.Values['HttpUrl'] := 'http://server/tunnel.php';UniConnection.SpecificOptions.Values['ProxyHostname'] := '10.0.0.1';UniConnection.SpecificOptions.Values['ProxyPort'] := '808';UniConnection.SpecificOptions.Values['ProxyUsername'] := 'ProxyUser';UniConnection.SpecificOptions.Values['ProxyPassword'] := 'ProxyPassword';UniConnection.Connect;

Note that setting the Proxy specific options automatically enables proxy server usage.

转载于:https://www.cnblogs.com/wxb-km/p/4378060.html

你可能感兴趣的文章
Android关于buildToolVersion与CompileSdkVersion的区别
查看>>
袋鼠云日志,日志分析没那么容易
查看>>
缓存穿透 缓存雪崩 缓存并发
查看>>
了解你的Linux系统:必须掌握的20个命令
查看>>
js setInterval 启用&停止
查看>>
knockoutJS学习笔记04:监控属性
查看>>
Linux下启动/关闭Oracle
查看>>
session和cookie的区别
查看>>
alert弹出窗口,点击确认后关闭页面
查看>>
oracle问题之数据库恢复(三)
查看>>
单点登陆(SSO)
查看>>
HR,也确实“尽职尽责”
查看>>
MaxComputer 使用客户端配置
查看>>
20190823 顺其自然
查看>>
阅读《余生有你,人间值得》有感
查看>>
每日英语
查看>>
SpringCloud+feign 基于Springboot2.0 负载均衡
查看>>
【BZOJ5094】硬盘检测 概率
查看>>
大庆金桥帆软报表案例
查看>>
Proxy模式
查看>>