2012-05-21 13:12
浏览 44


I'm trying to connect GWT with a PHP back-end; I successfully loaded some data in the front-end using the provided tutorial: https://developers.google.com/web-toolkit/doc/latest/DevGuideServerCommunication#DevGuideHttpRequests ; now I'm trying to send data from GWT to PHP using the same piece of code provided, but I don't know how I can modify it. In the Java GWT class I've done

RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(url));
    builder.setHeader("Content-Type", "application/json");
    try {
          Request request = builder.sendRequest("{\"data\":\"hello\"}", new RequestCallback() { ...

And then in the php script

echo json_decode($_POST);

But the error is "[INFO] [testapp] - Warning: json_decode() expects parameter 1 to be string, array given in C:\xampp\htdocs\TestApp\TestApp.php on line 25"

Can anyone provide a working example of this situation? Or link me some tutorial or document that talk more about how to use GWT with PHP? There is not so much in the official site...

图片转代码服务由CSDN问答提供 功能建议

我正在尝试将GWT与PHP后端连接; 我使用提供的教程成功地在前端加载了一些数据: https: //developers.google.com/web-toolkit/doc/latest/DevGuideServerCommunication#DevGuideHttpRequests ; 现在我正在尝试使用提供的相同代码将数据从GWT发送到PHP,但我不知道如何修改它。 在Java GWT类中,我已经完成了

  RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,URL.encode(url)); 
 builder.setHeader(“Content- 输入“,”application / json“); 
请求请求= builder.sendRequest(”{\“data \”:\“hello \”}“,新的RequestCallback(){... 
 <  / code>  


  echo json_decode($ _ POST); 

但错误是“[INFO] [testapp] - 警告:json_decode()期望参数1为字符串,数组在 C:\中给出 xampp \ htdocs \ TestApp \ TestApp.php 在行 25

任何人都可以提供这种情况的工作示例吗?或者链接我一些教程 或者说更多关于如何在PHP中使用GWT的文档?在官方网站上没有那么多......

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • doumao6212 2012-05-21 13:29
    echo json_decode($HTTP_ROW_POST_DATA);


    echo json_decode(file_get_contents("php://input"))

    See http://php.net/manual/en/reserved.variables.httprawpostdata.php and http://php.net/manual/en/wrappers.php.php (the latter should be preferred)

    解决 无用
    打赏 举报
  • drktvjp713333 2012-05-21 13:15

    Try this:

    echo json_decode($_POST['data']); 

    Because you want to decode your data parameter, not all posted parameters.

    解决 无用
    打赏 举报
  • dousongqiang2585 2012-05-21 13:45

    sendRequest takes data and send data as array. you have to use json_decode(parse_str($_POST['data'])) to receive Request data

    解决 无用
    打赏 举报

相关推荐 更多相似问题