开发者社区> 问答> 正文

hprose DELPHI 调用报错的问题?报错

procedure TForm1.Button2Click(Sender: TObject);
var
  client : THproseIdHttpClient;
begin
  client := THproseIdHttpClient(nil);
  //client.UseService('http://127.0.0.1/helloserver.php');
  client.UseService('http://www.hprose.com/example/');
  showmessage(client.Invoke('hello',['world']));
  client.Free;
end;

--------------------------------

 

 

展开
收起
爱吃鱼的程序员 2020-06-22 19:13:33 689 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    client:= THproseIdHttpClient.Create(nil);

    你创建对象的语句写错了。

    问题描述:

    我想用PHROSE来做数据传送,用PHP做服务器,DELPHI做客户端,定时发请求去取数据。现在是问是,想在发请求时先做个用户验证,结果php,没问题,DELPHI又有问题了,代码如下.另外一点,就是HPROSE的数据类型转换的PPT说明中能分类举例说明一下就跟好。谢谢!

    ========PHPServerCode============

    <?php
       include("hprose/php5/hproseHttpServer.php");

       $server=newHPRoseHttpServer();
       $server->addFunction('check_login');

       //登陆验证通过后发布
       if(isset($_SESSION["client_authorized"])&&$_SESSION["client_authorized"]==true)
       {
           require_once('./InterFaceFunList.php');
           $server->addFunction('hello');
           $server->addFunction('getQueryData');
       }

       functioncheck_login($username,$password){
           if(($username=='admin')&&($password=='123'))
           {
               $_SESSION["client_authorized"]=true;
               $_SESSION['admin']='admin';
               $_SESSION['password']='123';
               //$arr=array();
               //$arr['username']=$username;
               //$arr['password']=$password;
               returntrue;
           }
           else
           {
               returnfalse;
           }
       }
       $server->handle();
    ?>

    ================================

    =======DELPHIclientcode============

    procedureTForm1.Button4Click(Sender:TObject);
    var
     HPROSE1:THproseIdHttpClient;
     datas,rows:IList;
     br:boolean;
     i:Integer;
    begin
     HPROSE1:=THproseIdHttpClient.Create(nil);
     HPRose1.UseService('http://127.0.0.1/DataInterface.php');
     br:=HPRose1.Invoke('check_login',['admin','123']);//
     datas:=VarToList(HPRose1.Invoke('getQueryData',['user1','where1=1']));
     fori:=0todatas.Count-1do//报错'variantmethodcallsnotsuppoerted'
     begin
       rows:=VarToList(datas[i]);
       Memo1.Lines.Add('----------Line'+IntToStr(i+1)+'----------');
       Memo1.Lines.Add('id  ='+rows[0]);
       Memo1.Lines.Add('name   ='+rows[1]);
       Memo1.Lines.Add('password='+rows[2]);
     end;
    end;

     

     

     

    procedureTForm1.Button4Click(Sender:TObject);
    var
     HPROSE1:THproseIdHttpClient;
     datas,rows:IList;
     br:boolean;
     i:Integer;
    begin
     HPROSE1:=THproseIdHttpClient.Create(nil);
     HPRose1.UseService('http://127.0.0.1/DataInterface.php');
     br:=HPRose1.Invoke('check_login',['admin','123']);
     datas:=VarToList(HPRose1.Invoke('getQueryData',['user1','where1=1']));
     fori:=0todatas.Count-1do
     begin
       rows:=VarToList(datas[i]);
       Memo1.Lines.Add('----------Line'+IntToStr(i+1)+'----------');
       Memo1.Lines.Add('id  ='+rows[0]);
       Memo1.Lines.Add('name   ='+rows[1]);
       Memo1.Lines.Add('password='+rows[2]);
     end;
    end;做了验证后,DELPHI验证无效,就提示'getQueryData'此函数没发布!感觉对HProse的数据类型的转换不太会应用1 你没有写session_start()

    引用来自“andot”的评论

    你没有写session_start()

    引用来自“andot”的评论

    你没有写session_start()回复 @haitaosoft:session_start()这个是PHP里面的函数,上面这个问题是PHP和Delphi通过hprose通讯,传递session的问题。只要PHP服务部分开启了session,Delphi客户端会自动处理sessioncookie的。xe的新特性,不关心;关心的是session_start()这样的函数:还有哪些,什么情况下需要使用它们服务器端在哪,如何搭建服务器?
    2020-06-22 19:13:48
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
15分钟打造你自己的小程序 立即下载
小程序 大世界 立即下载
《15分钟打造你自己的小程序》 立即下载