概述
我正在尝试使用以下命令将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请求相当新,所以任何帮助将不胜感激.
最后
以上就是无奈水池为你收集整理的php json httpclient,php – 使用Zend_Http_Client发送json POST的全部内容,希望文章能够帮你解决php json httpclient,php – 使用Zend_Http_Client发送json POST所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复