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 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号