dongrendang6566 2016-08-23 14:30
浏览 44
已采纳

我是否需要在接收JSON HTTP POST的PHP脚本中专门处理HTTP响应?

I'll try again, as my last question wasn't written well enough.

I am writing a PHP script for handling the below JSON HTTP POSTrequest.

{
  "id": "621c46e4-2ca0-4254-a987-fc9e2cc7c552",
  "mobileNumber": 4799999999,
  "price": 20.5,
  "currency": "nok",
  "paymentDate": "2016-08-23T15:35:38.327104+02:00",
  "paymentType": "sms",
  "product": {
    "id": "17",
    "name": "PAPIRFLYET"
  },
  "success": true,
  "accessNumber": 2380,
  "dialog": [
    {
      "date": "2016-08-23T15:35:37.327104+02:00",
      "type": "mo",
      "message": "PAPIRFLYET",
      "consumerCharge": 0
    },
    {
      "date": "2016-08-23T15:35:38.827104+02:00",
      "type": "mt",
      "message": "Takk for din betaling",
      "consumerCharge": 20.5
    }
  ]
}  

I only want to send my self an email with the last 8 digits of mobileNumber.

    $json = file_get_contents("php://input");
    $obj = json_decode($json, true);

    $tlf = substr(strval($obj["mobileNumber"]),2,8);

    $email_from = "xxx@gmail.com";
    $email_to = "xxx@gmail.com";
    $email_subject = "Subject";
    $email_message = "Number is " . $tlf;

    $headers = "Content-type:text/html;charset=UTF-8" . "
";
    $headers .= 'From: ' . $email_from . "
";
    @mail($email_to, $email_subject, $email_message, $headers); 

If I just open my browser and go to the page mysite.com/json.php the email is sent (without any number obv), but when the POST request is sent nothing happens.

The client may be requesting a 100-continue, as indicated by the headers (when testing with posttestserver.com):

REQUEST_URI = /post.php
QUERY_STRING = 
REQUEST_METHOD = POST
GATEWAY_INTERFACE = CGI/1.1
REMOTE_PORT = 54820
REMOTE_ADDR = 193.142.108.232
HTTP_CONNECTION = close
HTTP_EXPECT = 100-continue
CONTENT_LENGTH = 638
HTTP_HOST = posttestserver.com
CONTENT_TYPE = application/json
UNIQUE_ID = V7xN1UBaMGUAAC@uOX4AAAAJ
REQUEST_TIME_FLOAT = 1471958485.5507
REQUEST_TIME = 1471958485

Do I need to specifically handle the HTTP reponses in my PHP script?

  • 写回答

1条回答 默认 最新

  • dongza1708 2016-08-23 21:27
    关注

    It seems like the problem was the wordpress hosting. If I put json.phpon mysite.com/json.php it worked fine. mysite.com/wp-content/themes/themeName/json.php did not work. I am not sure why, and neither does google, so I'll leave it at that :)

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

报告相同问题?

悬赏问题

  • ¥15 如何让子窗口鼠标滚动独立,不要传递消息给主窗口
  • ¥15 如何能达到用ping0.cc检测成这样?如图
  • ¥15 关于#DMA固件#的问题,请各位专家解答!
  • ¥15 matlab生成的x1图不趋于稳定,之后的图像是稳定的水平线
  • ¥15 请问华为OD岗位的内部职业发展通道都有哪些,以及各个级别晋升的要求
  • ¥20 微信小程序 canvas 问题
  • ¥15 系统 24h2 专业工作站版,浏览文件夹的图库,视频,图片之类的怎样删除?
  • ¥15 怎么把512还原为520格式
  • ¥15 MATLAB的动态模态分解出现错误,以CFX非定常模拟结果为快照
  • ¥15 求高通平台Softsim调试经验