- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试通过 cURL 发送 XML 文件。
除 header 外,一切正常, header 未正确发送。
为什么收不到?
test.php
$xml = file_get_contents("test.xml");
//These are the CUSTOM HEADERS being set in an array for later:
$data = array(
'x-meta-feed-type: Latest',
'x-meta-feed-parameters: feed params',
'x-meta-default-filename: '.time().'.xml',
'x-meta-game-id: f790722',
'x-meta-competition-id: c420',
'x-meta-season-id: 2014',
'x-meta-gamesystem-id: SUD_CL',
'x-meta-matchday: 7',
'x-meta-away-team-id: t2578',
'x-meta-home-team-id: t764',
'x-meta-game-status: 11',
'x-meta-language: en',
'x-meta-production-server: local',
'x-meta-production-server-timestamp: '.time(),
'x-meta-production-server-module: 1',
' x-meta-mime-type: text/xml',
'encoding: UTF-8'
);
//set URL
$url = 'http://www.example.com/receive.php';
// Get the curl session object
$session = curl_init($url);
// set url to post to
curl_setopt($session, CURLOPT_URL,$url);
// Tell curl to use HTTP POST;
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_HTTPHEADER, $data);
// Tell curl that this is the body of the POST
curl_setopt($session, CURLOPT_POSTFIELDS, $xml);
// Tell curl not to return headers, and return the response
curl_setopt($session, CURLOPT_HEADER, true);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
// allow redirects
curl_setopt($session, CURLOPT_FOLLOWLOCATION, true);
$response = curl_exec($session);
if (curl_errno($session)) {
print "Error: " . curl_error($session);
} else {
// Show me the result
echo $response;
curl_close($session);
}
curl_close($session);
receive.php
$headers = apache_request_headers();
$post_data = file_get_contents('php://input');
$posts = array (
'feedType' => isset($headers['x-meta-feed-type']) ? $headers['x-meta-feed-type'] : '',
'feedParameters' => isset($headers['x-meta-feed-parameters']) ? $headers['x-meta-feed-parameters'] : '',
'defaultFilename' => isset($headers['x-meta-default-filename']) ? $headers['x-meta-default-filename'] : '',
'deliveryType' => isset($headers['x-meta-game-id']) ? $headers['x-meta-game-id'] : '',
'messageDigest' => md5($post_data),
'competitionId' => isset($headers['x-meta-competition-id']) ? $headers['x-meta-competition-id'] : '',
'seasonId' => isset($headers['x-meta-season-id']) ? $headers['x-meta-season-id'] : '',
'gameId' => isset($headers['x-meta-game-id']) ? $headers['x-meta-game-id'] : '',
'gameSystemId' => isset($headers['x-meta-gamesystem-id']) ? $headers['x-meta-gamesystem-id'] : '',
'matchday' => isset($headers['x-meta-matchday']) ? $headers['x-meta-matchday'] : '',
'awayTeamId' => isset($headers['x-meta-away-team-id'])?$headers['x-meta-away-team-id']:'',
'homeTeamId' => isset($headers['x-meta-home-team-id']) ? $headers['x-meta-home-team-id'] : '',
'gameStatus' => isset($headers['x-meta-game-status']) ? $headers['x-meta-game-status'] : '',
'language' => isset($headers['x-meta-language']) ? $headers['x-meta-language'] : '',
'productionServer' => isset($headers['x-meta-production-server']) ? $headers['x-meta-production-server'] : '',
'productionServerTimeStamp' => isset($headers['x-meta-production-server-timestamp']) ? $headers['x-meta-production-server-timestamp'] : '',
'productionServerModule' => isset($headers['x-meta-production-server-module']) ? $headers['x-meta-production-server-module'] : '',
'mimeType' => 'text/xml',
'encoding' => isset($headers['x-meta-encoding']) ? $headers['x-meta-encoding'] : '',
'content' => $post_data
);
exit(print_r($posts));
输出
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Date: Mon, 05 Oct 2015 11:13:20 GMT
Server: Apache
X-Powered-By: PHP/5.4.45-0+deb7u1
Vary: User-Agent,Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html
Array
(
[feedType] =>
[feedParameters] =>
[defaultFilename] =>
[deliveryType] =>
[messageDigest] => 144ce144c73a12ea51a03ac1ef1256e5
[competitionId] =>
[seasonId] =>
[gameId] =>
[gameSystemId] =>
[matchday] =>
[awayTeamId] =>
[homeTeamId] =>
[gameStatus] =>
[language] =>
[productionServer] =>
[productionServerTimeStamp] =>
[productionServerModule] =>
[mimeType] => text/xml
[encoding] =>
[content] => File Content
) 1
最佳答案
如果我在 $headers
对象上使用 var_dump
(通过 apache_request_headers
检索),我会看到所有 header 标签都有它们的第一个大写字母:
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Date: Mon, 05 Oct 2015 11:30:20 GMT
Server: Apache
X-Powered-By: PHP/5.4.45-0+deb7u1
Vary: User-Agent,Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html
array(24) {
["Connection"]=>
string(5) "close"
["Expect"]=>
string(12) "100-continue"
["Content-Type"]=>
string(33) "application/x-www-form-urlencoded"
["Content-Length"]=>
string(5) "90166"
["Encoding"]=>
string(5) "UTF-8"
["X-Meta-Mime-Type"]=>
string(8) "text/xml"
["X-Meta-Production-Server-Module"]=>
string(1) "1"
["X-Meta-Production-Server-Timestamp"]=>
string(10) "1444044620"
["X-Meta-Production-Server"]=>
string(6) "server"
["X-Meta-Language"]=>
string(2) "en"
["X-Meta-Game-Status"]=>
string(2) "11"
["X-Meta-Home-Team-Id"]=>
string(4) "t764"
["X-Meta-Away-Team-Id"]=>
string(5) "t2578"
["X-Meta-Matchday"]=>
string(1) "7"
["X-Meta-Gamesystem-Id"]=>
string(6) "SUD_CL"
["X-Meta-Season-Id"]=>
string(4) "2014"
["X-Meta-Competition-Id"]=>
string(4) "c420"
["X-Meta-Game-Id"]=>
string(7) "f790722"
["X-Meta-Default-Filename"]=>
string(26) "opta-1444044620-bIb24r.xml"
["X-Meta-Feed-Parameters"]=>
string(11) "feed params"
["X-Meta-Feed-Type"]=>
string(6) "Latest"
["Accept"]=>
string(3) "*/*"
["Host"]=>
string(19) "example.com"
["User-Agent"]=>
string(109) "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36"
}
虽然这很奇怪 - 我很好奇为什么会发生这种情况,因为发送时 header 没有大写 - 解决方案是简单地更改接收页面以检查大写的自定义 header ,因为它们区分大小写.
关于php - 未正确接收 cURL header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32947225/
我以前从未做过任何 curl ,所以需要一些帮助。我试图从示例中解决这个问题,但无法理解它! 我有一个 curl 命令,我可以从 Windows 命令行成功运行该命令,该命令行在 Solr 中索引 p
curl -v有什么区别和 curl -I ? 我可以看到 -v是冗长的和 -I是标题。有什么具体的吗? 最佳答案 -I (大写字母 i)在 curl 中表示“没有正文”,对于 HTTP 表示发送 H
我正在使用curl php API访问FTP链接。在特定站点上,它给出错误代码9(拒绝访问)。但是,可以从IE和Firefox访问该链接。 然后,我运行curl命令行,它给出了相同的“访问拒绝”结果。
我已经使用curl有一段时间了,它可以正常工作,但是使用使用用户'domain\username'来验证curl的代理时,无法请求授权。授权方法是NTLM。此代码放入批处理文件中。 代码: curl
“curl”默认使用哪些证书? 例子: curl -I -L https://cruises.webjet.com.au 在 Ubuntu 15.04 上失败 curl: (60) SSL certi
我知道终端输出的一部分是请求的持续时间,剩余时间等。但是是否有一些文档指定了curl命令的终端输出的每一列到底是什么?手册页上的内容非常稀疏。 最佳答案 可能不容易找到,但已在the curl boo
我想通过 curl 在我自己的云服务器上的特定文件夹中上传文件。例如:http://www.myowncloudserver.com/remote.php/webdav/{MY_FOLDER}。此时我
我的网站上有一个密码保护的Web文件夹,我正在使用Curl在另一个域上获取该文件夹,我想要的是:当我尝试打开URL时,应该问我用户名和密码,而不是让它显示“需要授权”。 例: http://www.e
有没有一种方法可以通过简单的Curl获取Rabbitmq中队列的大小(剩余消息)? 类似于curl -xget http://host:1234/api/queue/test/stats 谢谢 最佳答
关闭。这个问题是opinion-based .它目前不接受答案。 2年前关闭。 锁定。这个问题及其答案是locked因为这个问题是题外话,但具有历史意义。它目前不接受新的答案或互动。 我最近开始在我的
我想访问需要用户名/密码的 URL。我想尝试用curl 访问它。现在我正在做类似的事情: curl http://api.somesite.com/test/blah?something=123 我收
我正在尝试使用 CURL 进行查询ElasticSearch 中的命令在windows平台。 例如:localhost:9200/playground/equipment/1?pretty 我收到一条
我正在尝试使用 Docker 构建和运行 Marklogic 实例。 Marklogic 提供了一些不错的 http api,所以,作为最终 CMD在 Dockerfile 中,我运行两个脚本,它们通
我正在尝试通过 cURL 检索网页的内容(比方说 http://www.foo.com/bar.php )。 当我在浏览器中加载网站时,加载页面时会出现动画,页面最终会显示出来。 但是使用 cURL,
我正在尝试使用带代理的命令行 CURL 获取响应状态代码。 这会返回整个页面,但我只想要状态代码。我怎么做?谢谢。 curl -sL -w -x IP:PORT "%{http_code}\n""ht
我有一段代码检查 http/s 端点的状态和加载时间。然后我会为每个顶级页面检查 1 级 href,以检查页面引用的所有内容是否也加载了 200。 (我查了50个顶级页面,每个顶级页面平均有8个链接)
curl --upload-file 和 curl --form file=@/path/file 有什么区别?这些 HTTP 请求有何不同? 最佳答案 --上传文件 (使用 HTTP 或 HTTPS
我正在尝试使用 system-curl 安装 cmake,使用 ./bootstrap --system-curl,如 here 所示.这样做,我得到了: -- Could NOT find
我需要使用 Curl 下载 Youtube 视频的特定部分。 (假设我想下载前 2MB)我在 Curl 中使用 -r 开关来实现这一点。它适用于非 YouTube 链接,但 Youtube 链接会忽略
我希望在使用 curl 命令从远程服务器下载文件后,将时间戳或日期添加到文件名中。我知道您可以使用 -o 来指定您要为文件命名的内容。我看到过这样的建议:-o "somefile $(date +\"
我是一名优秀的程序员,十分优秀!