javascript - 如何在 php 页面中显示 javascript
问题描述
我将如何在 php 页面中显示此信息?我从我的广告供应商的 API 指南中获得了这个脚本。
谢谢!
<html>
<head>
<script type="text/javascript">
var request = require('request'); // npm package request
request.post(
'http://udmserve.com/udm/radalytics_api.cpx?action=report&api_key=xxx',
{ json: {"start_date":"2018-10-28","end_date":"2018-10-29", "columns":["paid_impressions","revenue"]} },
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body)
}
}
);
</script>
</head>
<body>
<h1>
the rev is:
<script type="text/javascript">
document.write(request)
</script>
</h1>
</body>
</html>
解决方案
如果要从 PHP 代码发送 POST 请求,可以使用Guzzle库。
首先,您应该使用Composer安装 Guzzle ,然后您可以轻松使用 Guzzle 并发送您的 POST 请求。
$client = new GuzzleHttp\Client();
$response = $client->post('http://udmserve.com/udm/radalytics_api.cpx?action=report&api_key=xxxx', [ 'json' => [
'start_date' => '2016-08-02',
'end_date' => '2016-08-03',
'columns' => ["paid_impressions", "revenue"]
]]);
推荐阅读
- ios - 使用 UIDocumentPickerViewController 时如何快速从 CSV 获取数据
- java - java字符串池中会创建多少个String对象?
- javascript - Discord.js Bot 忽略前缀并且会响应前面的任何内容
- amazon-web-services - 如何使用新密钥对(新 pem 文件)连接到 aws 实例
- docker - 还通过 Nginx 路径中的端口?
- sql - 如何使用lua脚本在xml中获取段落长度
- python-3.x - 在处理数据时如何保持 websocket 处于活动状态?
- android - 如何合并来自firestore中两个集合的数据?
- javascript - JavaScript 在构造函数之外创建一个对象并添加 2 个方法
- r - 如何重命名数据框中的第 0 列?