doufei4923 2011-01-27 15:47
浏览 92
已采纳

C#与PHP脚本通信

I'm trying to implement a simple login system in my application. The C# application would send a POST request with user id and password to the PHP script. Then the PHP script would check if the user id exists, and if the password is correct. If yes, it would return some data(time left, unique id). I'm not sure how to return the data to my application though, what would be the best way in your opinion?

Thanks.

  • 写回答

2条回答 默认 最新

  • dtnwm4807 2011-01-27 15:49
    关注

    Just echoing it in the response body as usual would be the most obvious option. If it's more complex data, you could use a standard like json_encode() that you can parse in C#.

    Example:

    $data["time_left"] = 12023932103129;
    $data["unique_id"] = 203032924420;
    
    echo json_encode($data);  // will output a JSON string that you can decode
                              // in C#.
    

    Additionally, you could consider using status codes for error handling, for example:

    if ($error)
     {
       header("HTTP/1.1 500 Internal Server Error");
       echo "Details of the error in here";
     }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作