我想用Curl发送复杂的Post数据.
我尝试发送的数据:
Array
(
[test] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
[file] => CURLFile Object
(
[name] => H:\wwwroot\curl/upload.txt
[mime] =>
[postname] =>
)
)
Run Code Online (Sandbox Code Playgroud)
我需要使用post-side中的变量作为$ _POST ["test"]和$ _FILES ["file"]但我无法实现.对于(有时是多维的)数组数据,我需要http_build_query但是会破坏文件.如果我不使用http_build_query,我的数组会给出"数组到字符串转换"错误.
我怎样才能使这个工作?码:
的index.php
$curl = curl_init();
$postValues = Array("test" => Array(1,2,3));
$postValues["file"] = new CurlFile(dirname(__FILE__). "/upload.txt");
curl_setopt($curl, CURLOPT_URL, "localhost/curl/post.php");
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postValues);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$curlResult = curl_exec($curl);
$curlStatus = curl_getinfo($curl);
echo $curlResult;
Run Code Online (Sandbox Code Playgroud)
post.php中
print_r($_REQUEST);
print_r($_FILES);
Run Code Online (Sandbox Code Playgroud) 我想为 Chrome 编写一个扩展程序来观看我的 XHR 调用,我发现我必须为此使用 webRequest。
我想获得请求的响应正文,但我永远找不到如何做到这一点。这可能吗?
// chrome.browserAction.onClicked.addListener(function (tab) {
var callback = function(details) {
var url = details.url;
console.log(details);
};
var filter = {
urls: ["*://safan.dev/*"]
};
var ops = ["requestBody"];
chrome.webRequest.onBeforeRequest.addListener(
callback, filter, ops
);
// });
Run Code Online (Sandbox Code Playgroud)
并体现:
{
"manifest_version": 2,
"name": "Forge of Empires",
"description": "FOE",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png"
},
"permissions": [
"webRequest",
"<all_urls>"
],
"background": {
"scripts": ["logic.js"]
}
}
Run Code Online (Sandbox Code Playgroud)