(* Collection of code snippets by Arne Vajhøj *)
(* (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) *)
[inherit('phttpdir:phttp')]
program p4(input,output);

procedure test(host : pstr; port : integer; path : pstr);

var
   con : http;
   outmsg, inmsg : pstr;

begin
   (* connect and write request message *)
   outmsg := 'Hi from Pascal!' + chr(13) + chr(10);
   con := http_post(fix(host), port, fix(path), 'text/plain', '*/*', fix(outmsg));
   (* read response message *)
   if http_numcode(con) = 200 then begin
      while http_recv(con, inmsg.body, inmsg.length) >= 0 do begin
         writeln(inmsg);
      end;
   end else begin
      writeln('HTTP error : ', http_numcode(con):1, ' (', http_txtcode2(con), ')');
   end;
   (* disconnect *)
   http_close(con);
end;

begin
   test('arne1', 12345, '/');
   test('arne1', 12346, '/');
end.
