我是否需要在接收 JSON HTTP POST 的 PHP 脚本中专门处理 HTTP 响应?
Do I need to spesifically handle HTTP reponse in my PHP script that receives JSON HTTP POST?
我会再试一次,因为我的最后一个问题写得不够好。
我正在编写一个 PHP
脚本来处理下面的 JSON HTTP POST
请求。
{
"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
}
]
}
我只想给自己发一封包含 mobileNumber
后 8 位数字的电子邮件。
$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" . "\r\n";
$headers .= 'From: ' . $email_from . "\r\n";
@mail($email_to, $email_subject, $email_message, $headers);
如果我只是打开浏览器并转到页面 mysite.com/json.php
,则会发送电子邮件(没有任何数字 obv),但是当发送 POST
请求时,什么也没有发生。
客户端可能正在请求 100-continue
,如 headers 所示(使用 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
我是否需要在 PHP 脚本中专门处理 HTTP 响应?
问题似乎出在 wordpress 托管上。如果我把 json.php
放在 mysite.com/json.php
上,它工作正常。 mysite.com/wp-content/themes/themeName/json.php
无效。我不确定为什么,google 也不知道,所以我就此打住 :)
我会再试一次,因为我的最后一个问题写得不够好。
我正在编写一个 PHP
脚本来处理下面的 JSON HTTP POST
请求。
{
"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
}
]
}
我只想给自己发一封包含 mobileNumber
后 8 位数字的电子邮件。
$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" . "\r\n";
$headers .= 'From: ' . $email_from . "\r\n";
@mail($email_to, $email_subject, $email_message, $headers);
如果我只是打开浏览器并转到页面 mysite.com/json.php
,则会发送电子邮件(没有任何数字 obv),但是当发送 POST
请求时,什么也没有发生。
客户端可能正在请求 100-continue
,如 headers 所示(使用 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
我是否需要在 PHP 脚本中专门处理 HTTP 响应?
问题似乎出在 wordpress 托管上。如果我把 json.php
放在 mysite.com/json.php
上,它工作正常。 mysite.com/wp-content/themes/themeName/json.php
无效。我不确定为什么,google 也不知道,所以我就此打住 :)