我必须发出post请求,并使用postman进行测试。现在,代码库使用php,我以前从未使用过php。在检查邮差中的代码部分时,我得到了这个:
CURLOPT_POSTFIELDS =>'{"datalist":[{
"Firstname":"firstname",
"Lastname":"lastname4",
"Email":"lead@test2.com",
"Phone":"9899999999",
"leadsource":"Website",
"address":"lakeview",
"pincode":"440010",
"Grade":"Class 1",
"utmcampaign":"summer_sale",
"utmcontent":"video_ad",
"utmmedium":"organic_social",
"utmterm":"social_media",
}
]}'
问题是,我必须传递动态值,而不是firstname, lastname4等。我的值存储为$lead['name']
.
所以,基本上我必须传递$lead['name']
而不是lastname4,但我无法弄清楚语法。
您可以在数组上使用json_encode
来构建所需的JSON字符串
$arr=array(
'datalist'=>array( array(
'Firstname'=>$lead['name'],
'Lastname'=>$lead['last'],
'Email'=>$lead['email'],
'Phone'=>$lead['phone'],
'leadsource'=>$lead['website'],
/*... etc */
)
) );
CURLOPT_POSTFIELDS=json_encode( $arr );