【发布时间】:2018-11-26 11:15:12
【问题描述】:
我目前正在尝试实现一个将数据发布为“multipart/form-data”的系统,并且我正在通过 php://input 接收数据,如下所示:
[
{
"id":"595944535043",
"companyProfileID":"",
"accountID":"",
"ownerID":"",
"importID":"",
"avatarUrl":"https://d2ojpxxtu63wzl.cloudfront.net/static/a9b1a30bbf8148445118d0d70ebd4a01_16edde90d640c6ee84a1874a4dbb3cdc816bc9e94ec6a23efc885e59947b28ab",
"companyName":"",
"title":"",
"firstName":"Madison",
"lastName":"Test",
"street":"",
"city":"",
"country":"",
"state":"",
"zipcode":"",
"emailAddress":"email@email.com",
"website":"",
"phoneNumber":"",
"officePhoneNumber":"",
"phoneNumberExtension":"",
"mobilePhoneNumber":"",
"faxNumber":"",
"description":"",
"campaignID":"",
"crmLeadID":"",
"crmOpportunityID":"",
"crmAccountID":"",
"crmContactID":"",
"crmOwnerID":"",
"crmThirdPartyID":"",
"formGUID":"",
"trackingID":"",
"leadSource":"",
"industry":"",
"active":"1",
"isQualified":"",
"isContact":"1",
"isCustomer":"0",
"hasOpportunity":"0",
"lastActivityDate":"2018-06-08 15:04:10",
"updateTimestamp":"2018-06-17 09:25:39",
"updateUserProfileID":"0",
"createTimestamp":"2018-06-08 14:04:10",
"createUserProfileID":"313407940",
"leadStatus":"contact",
"persona":"",
"services_5addf517bd49b":""
}
]
但是,当我尝试通过 $_POST 访问这些详细信息时,它不会返回任何内容。快速检查表明 $_POST 实际上是空的。
我已经用尽了关于这个问题的所有选项 php $_POST array empty upon form submission
还有这个PHP some $_POST values missing but are present in php://input
将我的 max_input_vars 更改为 10000,post_max_size 为 1G。试过 JSON decode 解决方案,parsestr 解决方案,什么都没有。
所以只是想知道是否有人可以提供帮助?
不是重复的问题,因为数据是嵌套的。与之前的堆栈溢出问题不同
【问题讨论】:
-
首先阅读 POST fields 和 POST body ,然后
$posted_data = json_decode(file_get_contents("php://input")); -
这两种方法我都试过了。
$posted_data的 var_dump 不返回任何内容 -
您能添加请求的来源吗?即向 PHP 发送请求的代码部分的代码。
-
Not a duplicated question as the data is nested. Different to previous problems on Stack overflow这是因为你不能在$_POST中使用 JSON,$_POST是一个 PHP 预设置变量,如果它在标准输入流中,它使用与parse_str相同的东西php://input只需阅读它就可以将其解析为不同的 var EG$json = json_decode(file_get_contents("php://input"));然后您可以像$json[0]->id一样使用它 -
请注意 Sharpspring 提供数据的额外方括号,这意味着此处之前的问题不适用于此问题。我还没有找到任何使用
$json[0]->id的先前答案
标签: php post multipartform-data