WebTcpipRecv Function

Action

Retrieves data from the remote host.

Include file

WebAPI.bdh

Syntax

WebTcpipRecv( in  hWeb      : number,
              out sData     : string allownull,
              in  nMaxData  : number optional,
              out nReceived : number optional): boolean;

Return value

  • true if up to nMaxData bytes could be read successfully

  • false otherwise

Parameter Description
hWeb Valid handle to a Web connection that was created by WebTcpipConnect
sData

Buffer to store the received data.

This field may be set to NULL to use only internal buffers, for example, if result is not to be parsed

nMaxData

Maximum amount of data to read from server.

This value has no effect when sData is set to NULL.

nReceived Parameter that receives the actual amount of data received from the server. Often more calls to WebTcpipRecv are needed to get all the data from the server.

Example

// Sample to retrieve an HTML page from a Web server
dcltrans
  transaction TWebRecv
  var
    hWeb0 : number;
    nRecv : number;
    sData : string;
  begin
    WebTcpipConnect(hWeb0, "purple", 80);
    WebTcpipSend(hWeb0, "GET / HTTP/1.0\r\n"
    "User-Agent: CustomClient/1.0\r\n"
    "Accept: */*\r\n\r\n");
    // Wait until WebRecv returns with 0 bytes read
    loop
    if not WebTcpipRecv(hWeb0, sData, 1000, nRecv) then
    write("error"); writeln;
  end;

    if nRecv = 0 then exit; end;
      write(nRecv); writeln;
      write(sData); writeln;
    end;

    writeln;
    WebTcpipShutdown(hWeb0);
  end TWebRecv;