php json httpclient,php – 使用Zend_Http_Client发送json POST

我正在尝试使用以下命令将json对象作为POST命令发送:

$uri = "http://amore-luce.com/product_create";

$product = $observer->getEvent()->getProduct();

$json = Mage::helper('core')->jsonEncode($product);

Mage::log(" Json={$json}", null,'product-updates.txt');

// new HTTP request to some HTTP address

$client = new Zend_Http_Client('http://amore-luce.com/product_create');

// set some parameters

$client->setParameterPost('product', $json);

// POST request

$response = $client->request(Zend_Http_Client::POST);

当我查看$json数据时,所有数据都很好 – 但POST不发送json数据.我正在使用一个简单的电子邮件表单捕获它,该表单应该向我发送响应:

$webhookContent = "";

$ref = "";

$webhook = fopen('php://input' , 'rb');

while (!feof($webhook)) {

$webhookContent .= fread($webhook, 4096);

}

fclose($webhook);

$headers = array();

foreach($_SERVER as $key => $value) {

if (substr($key, 0, 5) <> 'HTTP_') {

continue;

}

$header = str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))));

$headers[$header] = $value;

}

foreach ($headers as $header => $value) {

$ref .= "$header: $value
\n";

}

$post = file_get_contents('php://input');

$to = "address@my-email.com"; //the address the email is being sent to

$subject = "This is the subject"; //the subject of the message

$msg = "This is the message - Webhook content: ".$webhookContent." This is url: ".$ref; //the message of the email

mail($to, $subject, $msg, 'From: PHP Scriptv2 '); //send the email.

echo ($_SERVER['HTTP_REFERER']."
".$_SERVER['REQUEST_URI']);

?>

此页面适用于我发送给它的其他json POST请求.我发送POST请求相当新,所以任何帮助将不胜感激.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值