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 :)

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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!