dongtu1789 2016-09-25 19:27
浏览 152
已采纳

Eclipse PDT中Chrome PostMan插件的POST数据为空

I am trying to debug HTTP POST data sent to some AJAX PHP in Eclipse PDT and it is new to me, so I am probably making some very basic mistake.

I found what seems to be an excellent Chrome browser plugin: PostMan

I have defined my request thus:

enter image description here

Which is trying to emulate my AngulrJs code (which works)

   var postData = { userName: $scope.registrationData.userName,
                    email:    $scope.registrationData.email,
                    password: forge_sha256($scope.registrationData.password)
                  };

   var url = HOST + 'api/register.php';

   $http.post(url, postData)

If I just use the AngularJs from a browser page, it works and the PHP returns what I expect it to.

BUT, when I use Postman, then in my PHP code

   $postData = file_get_contents("php://input");
   $request = json_decode($postData, true);

I find that $_POST is empty.

What am I doing wrongly (or is there a simpler way to debug HTTP Post with Eclipse PDT)?


[Update] Thanks, @Rubelet, for pointing out that the POST data should go in the body, not the headers.

If I encode it as form data

enter image description here

the received POST data is still empty. I am guessing that I should use "raw", but how do I encode? As JSON?

  • 写回答

1条回答 默认 最新

  • dongyou9373 2016-09-25 19:44
    关注

    You are embedding your data in the Header section of PostMan. These are for HTTP Headers and not what you want. When using angular's post method, the parameters are in fact embedded into the Body section of a POST request.

    Put your parameters in the Body section of Postman and it should work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示