|
|
|
|
|
- Security error in a secure transaction
- Retrieving the result
- Accessing a password-protected URL
- Using a proxy
- Authentication headers
- Required permissions
- Limitations
- Required application feature
HTTPRequest (Function) In french: HTTPRequête
Warning
From version 28, this function is kept for compatibility only (especially for PHP programming). It is recommended to use a variable of type httpRequest with the HTTPSend function.
Starts an HTTP request on a server. The result of the query (buffer) can be: Remarks: - Two types of requests are supported: POST and GET. The GET requests are automatic. If the "Message to send" is not specified, it is a GET request (see the syntax). To manage forms, it is recommend to use form-specific functions (HTTPCreateForm, HTTPSendForm, etc.).
- HTTPRequest can be used only if the use of sockets is allowed on the PHP server. For an URL in HTTPS, OpenSSL must be compiled with the PHP engine used to generate the pages: http://www.php.net/
// Retrieve the HTML code of "www.windev.com" Web page ResStart = HTTPRequest("http://www.windev.com") // Retrieve an HTML page that uses a protected URL ResStart = HTTPRequest("http://www.windev.com", ... "", "", "", "", "Julia", "Password") Syntax
<Result> = HTTPRequest(<URL to contact> [, <User agent> [, <Additional HTTP header> [, <Message to send> [, <Message type> [, <Username> [, <Password>]]]]]])
<Result>: Boolean - True if the request was started,
- False if an error occurs. To get more details on the error, use ErrorInfo with the errMessage constant.
The result of the request can be saved in a backup file by HTTPDestination or it can be retrieved by HTTPGetResult. The errors regarding the security of transactions are not returned by ErrorInfo: the connection is refused.
<URL to contact>: Character string Address of server to contact (URL address). This parameter can contain:- the port number for connecting to the server. The default value is 80 (corresponds to a server of Web pages). To specify a port number, use the following format: "<Server URL>:<Port #>". For example: http://www.windev.com:80.
- additional parameters. These parameters can be used to perform a search or to fill a form. For example, to find "windev" on "http://www.google.com", the URL to contact will be: "http://www.google.com/search?q=windev".
Remarks: - To specify both the port number and additional parameters, use the following format: "<Server URL>:<Port #>/<Additional parameters>".
- To perform a secure transaction, the URL must start with "https://". In this case, the management mode of requests is always performed by Internet Explorer (for more details, see HTTPConfigure).
<User agent>: Optional character string Identifies the client. The application name is returned by default. The content of the response may depend on the user agent (for example, a request performed from a mobile device and a request performed from a PC browser require different pages). In this case, for more details, see the documentation of user agent. <Additional HTTP header>: Optional character string - Additional HTTP header that will be added to the HTTP message,
- Empty string ("") if no HTTP header must be added.
<Message to send>: Optional character string HTTP message that will be sent to the server. This parameter can be specified only for a request for sending messages (POST request). The message to send must comply with the HTTP protocol used. If this parameter is specified and if it is not empty, it is a POST request; otherwise, it is a GET request (everything else is automatic). <Message type>: Optional character string Type of the HTTP message content to be sent to the server. This parameter can be specified only for a request for sending messages (POST request). This parameter corresponds to "Content-Type". By default, the message type corresponds to: "application/x-www-form-urlencoded". However, you have the ability to use any value, for example: "text/xml", "application/javascript", "application/json", "application/xml", "image/jpeg", ...
To send rough data that will be read at once by the WEBDEV Application Server, use the following types: - "application/octet-stream".
- "text/xml".
<Username>: Optional character string Name used to access a page with a protected URL (empty string by default). This name is used to identify the user.Remark: When the <Username> and <Password> parameters are specified, the corresponding "Authorization:Basic" request header is automatically generated.
<Password>: Optional character string Password associated with the username (empty string by default). Used to access a page with a protected URL. Caution: The password is not encrypted when it is sent over the Internet.Remark: When the <Username> and <Password> parameters are specified, the corresponding "Authorization:Basic" request header is automatically generated.
Remarks Security error in a secure transaction During a secure transaction, the request may fail due to security errors: - invalid certificate or certificate coming from an unknown company.
- the site name specified in the certificate does not correspond to a server.
- invalid or expired certificate date.
- redirection to a non-secure server.
- ...
If one of these errors occurs, you can re-run the request while ignoring the errors. To do so, use the HTTP.IgnoreError variable. The HTTP.IgnoreError variable can also be used to manage special cases during the secure transactions (ignoring the list of revoked certificates for example). | | | Error returned by ErrorInfo (with the errCode constant) | Value of HTTP.IgnoreError (these values can be combined) | Description |
---|
httpErrorInvalidCertificate Invalid certificate or certificate coming from an unknown company | httpIgnoreInvalidCertificate | The certificate is ignored. | httpErrorInvalidCertificateName The site name specified in the certificate does not correspond to a server | httpIgnoreInvalidCertificateName | The site name specified in the certificate is ignored. | httpErrorExpiredCertificate Invalid or expired certificate date | httpIgnoreExpiredCertificate | The certificate date is ignored | httpErrorRedirectToHTTP Redirection to a non-secure server | httpIgnoreRedirectToHTTP | The redirection to a non-secure server is allowed. | httpIgnoreRedirectToHTTPS Redirection to a secure server | httpIgnoreRedirectToHTTPS | The redirection to a secure server is allowed. | | httpIgnoreRedirection | The redirection to a page is ignored. | | httpIgnoreRevocation | The certificate found in the list of revoked certificates is not checked. |
For example:
ResStart = HTTPRequest("https://www.MyServer.com")
IF ResStart = False THEN
SWITCH ErrorInfo(errCode)
CASE httpErrorInvalidCertificate:
IF YesNo("Security alert detected!", ...
"Invalid certificate.", ...
"Ignore this certificate?") = Yes THEN
HTTP.IgnoreError = httpIgnoreInvalidCertificate
HTTPRequest("https://www.MyServer.com")
END
CASE httpErrorExpiredCertificate:
IF YesNo("Security alert detected!", ...
"Certificate date invalid or expired.", ...
"Ignore this date?") = Yes THEN
HTTP.IgnoreError = httpIgnoreExpiredCertificate
HTTPRequest("https://www.MyServer.com")
END
END
END
Remarks: - When the HTTP queries are run in several threads, the HTTP.IgnoreError variable has a specific value for each thread.
- The errors regarding the security of transactions are ignored. The HTTP.IgnoreError variable is not available.
-
Before version 200057, the errors regarding the security of transactions were ignored. The HTTP.IgnoreError variable was not available. From version 200057, the following errors are supported: httpIgnoreExpiredCertificate, httpIgnoreInvalidCertificate, httpIgnoreInvalidCertificateName, httpIgnoreRevocation. The other errors are ignored. For backward compatibility, all the errors are ignored on the existing projects. These errors are supported on the new projects only. The httpIgnoreRedirection error is also supported.
Retrieving the result HTTPGetResult is used to retrieve the result of the last HTTP request run. - when HTTPGetResult is used with the httpResult constant, it always returns an empty string ("").
- HTTPGetResult associated with the httpHeader constant always returns the header of the HTTP response. This header is not saved in the destination file: only the data is saved.
When the request is over, the destination is canceled and HTTPRequest operates as usual.
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|