在Delphi中使用Localhost

时间:2015-01-31 19:25:46

标签: lazarus freepascal

大家晚上,

昨天给了意识形态,所以我一直在花时间学习德尔福。 我想发送数据到URL(使用GET请求/ Wininet)现在我在delphi程序中使用http://localhost时遇到问题,就像我尝试使用像http://localhost这样的localhost时,它会评论其他指令连接

我正在使用Lazarus,我的代码就像这样

program InfoWininet;

{$mode delphi}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes , Windows , Wininet
  { you can add units after this };

var
  FirstName : string;
  LastName: string;
  Email: string ;
  IDNumber: string;
  IOpen, IURL: HINTERNET;
  Read: Cardinal;
  data: string;
  Result : string;
  http : HINTERNET;

begin
    Writeln('Enter Your First Name: ');
    Readln(FirstName);
    Writeln('Enter your Last Name: ');
    Readln(LastName);
    Writeln('Enter Your Email: ');
    Readln(Email);
    Writeln('Enter your ID Number: ');
    Readln(IDNumber);

    data := http://localhost/data.php?fname=' + FirstName + '&lastName=' + LastName + '&Email=' + Email +  '&IdNumber=' + IDNumber;
   begin
    Result:='';
    try
     IOpen := InternetOpen('Oxysys',INTERNET_OPEN_TYPE_PRECONFIG, '', '',INTERNET_FLAG_NEED_FILE);
      if IOpen<>nil then
        try
        IURL:= InternetOpenUrl(IOpen, data, nil, 0,INTERNET_FLAG_DONT_CACHE, 0);
    if IURL<> nil then
        try
          SetLength(data,4096);
        repeat
    if InternetReadFile(IURL,@data[1],4096,Read) then
    Result:=Result + Copy(data,1,Read)
        else
        Break;
    until Read = 0;
    finally
      InternetCloseHandle(IURL);
    end;
    finally
      InternetCloseHandle(IOpen);
        end;
          except
    end;
          Writeln('Message Sent Successfully...');
          Readln;
end;
end.

问题是我在尝试编译程序时遇到以下错误

InfoWininet.lpr(33,13) Warning: Variable "http" does not seem to be initialized
InfoWininet.lpr(33,13) Error: Incompatible types: got "Pointer" expected "AnsiString"
InfoWininet.lpr(33,17) Fatal: Syntax error, ";" expected but ":" found

真正的问题是什么?有人可以帮忙,纠正问题,请尽快学习Delphi。

1 个答案:

答案 0 :(得分:1)

data := http://localhost/data.php?fname=' + FirstName + '&lastName=' + LastName + 
  '&Email=' + Email +  '&IdNumber=' + IDNumber;

您无法将字符串文字包装在引号中。它应该是:

data := 'http://localhost/data.php?fname=' + ....
        ^
    quote missing here