4D v14.3

HTTP Get

Home

 
4D v14.3
HTTP Get

HTTP Get 


 

HTTP Get ( url ; response {; headerNames ; headerValues}{; *} ) -> Function result 
Parameter Type   Description
url  Text in URL to which to send the request
response  Text, BLOB, Picture, Object in Result of request
headerNames  Text array in Header names of the request
in Returned header names
headerValues  Text array in Header values of the request
in Returned header values
Operator in If passed, connection is maintained (keep-alive)
If omitted, connection is closed automatically
Function result  Longint in HTTP status code

The HTTP Get command sends an HTTP GET request directly to a specific URL and processes the HTTP server response.

Pass the URL where you want the request sent in the url parameter. The syntax to use is:

http://[{user}:[{password}]@]host[:{port}][/{path}][?{queryString}]

For example, you can pass the following strings:

    http://www.myserver.com
    http://www.myserver.com/path
    http://www.myserver.com/path?name="jones"
    https://www.myserver.com/login (*)
    http://123.45.67.89:8083
    http://john:smith@123.45.67.89:8083

(*) During HTTPS requests, authority of the certificate is not checked.

After command execution, the response parameter receives the result of the request returned by the server. This result corresponds to the body of the response, with no headers.
You can pass different types of variables in response:

  • Text: When the result is expected to be text encoded in UTF16
  • BLOB: When the result is expected to be in binary form. 
  • Picture: When the result is expected to be a picture.
  • Object: When the result is expected to be a C_OBJECT object.

If you pass a BLOB, it contains the text, picture or any type of contents (.wav, .zip, etc.) returned by the server. You must then manage the recovery of these contents (headers are not included in the BLOB). If the type of data returned by the server does not match the variable type, it is returned empty. When you pass a C_OBJECT type object, if the request returns a result with an "application/json" (or "something/json") content-type, 4D attempts to parse the JSON content in order to generate the object.

In headerNames and headerValues, you pass arrays containing the names and values of the request headers.
After this method is executed, these arrays contain the names and values of headers returned by the HTTP server. More specifically, this lets you manage cookies. 

The * parameter enables the keep-alive mechanism for the server connection. By default, if this parameter is omitted, keep-alive is not enabled. 

The command returns a standard HTTP status code (200=OK and so on) as returned by the server. The list of HTTP status codes is provided in RFC 2616.
If you are unable to connect to the server for a reason related to the network (DNS Failed, Server not reachable...), the command returns 0 and an error is generated. If the command uses a server certificate and this certificate is not valid (expired or revoked), the command returns 0 and the error 901 "Server certificate invalid" is returned. You can intercept these errors using an error-handling method installed by the ON ERR CALL command.

Retrieval of the 4D logo on the 4D Web site:

 C_TEXT(URLPic_t)
 URLPic_t:="http://www.4d.com/sites/all/themes/dimention/images/home/logo4D.jpg"
 ARRAY TEXT(HeaderNames_at;0)
 ARRAY TEXT(HeaderValues_at;0)
 C_PICTURE(Pic_i)
 $httpResponse:=HTTP Get(URLPic_t;Pic_i;HeaderNames_at;HeaderValues_at)

Retrieval of an RFC:

 C_TEXT(URLText_t)
 C_TEXT(Text_t)
 URLText_t:="http://tools.ietf.org/rfc/rfc1.txt"
 ARRAY TEXT(HeaderNames_at;0)
 ARRAY TEXT(HeaderValues_at;0)
 $httpResponse:=HTTP Get(URLText_t;Text_t;HeaderNames_at;HeaderValues_at)

Retrieval of a video:

 C_BLOB(vBlob)
 $httpResponse:=HTTP Get("http://www.example.com/video.flv";vBlob)
 BLOB TO DOCUMENT("video.flv";vBlob)

 
PROPERTIES 

Product: 4D
Theme: HTTP Client
Number: 1157

This command modifies the Error system variable

 
HISTORY 

New
Created: 4D v13
Modified: 4D v14

 
SEE ALSO 

HTTP Request

 
ARTICLE USAGE

4D Language Reference ( 4D v14 R2)
4D Language Reference ( 4D v14 R3)
4D Language Reference ( 4D v14.3)
4D Language Reference ( 4D v14 R4)

Inherited from : HTTP Get ( 4D v13.5)