HttpSendRequest

Ukázka odeslání HTTP požadavku

Popis

Skript odešle HTTP požadavek. Následně zobrazí stavový kód a tělo odpovědi serveru.
declare function HttpCreate dll "ScriptEx" (string): integer
declare procedure HttpFree dll "ScriptEx" (var integer)

declare function HttpGetIntegerProp dll "ScriptEx" (integer, string): integer
declare function HttpGetStringProp dll "ScriptEx" (integer, string): string
declare procedure HttpSetStringProp dll "ScriptEx"(integer, string, string)

declare function HttpConnectionSendRequest dll "ScriptEx" (integer, integer): integer

declare function LastErrorGetCode dll "ScriptEx" (): integer
declare function LastErrorGetMessage dll "ScriptEx" (): string

script HttpSendRequest(): boolean
var
  Connection: integer
  Request: integer
  Response: integer
begin
  Connection := HttpCreate("THttpConnection")

  HttpSetStringProp(Connection, "Host", "httpbin.org")

  Request := HttpCreate("THttpRequest")

  HttpSetStringProp(Request, "Method", "GET")
  HttpSetStringProp(Request, "Path", "html") // http://httpbin.org/html

  Response := HttpConnectionSendRequest(Connection, Request)

  if Response <> 0 then
    write("STATUS: " + HttpGetIntegerProp(Response, "StatusCode"))
    write(HttpGetStringProp(Response, "Body"))

    result := true
  else
    write("ERROR: " + LastErrorGetMessage())

    result := false
  end

  HttpFree(Request)
  HttpFree(Connection)
end