php - 未使用 PHP/Curl 从 Deutsche Bahn API 获得响应
问题描述
我正在使用 Deutsche Bahn Api 获取欧洲的火车记录,但 API 返回错误:
该文件已移动https://www.bahn.de/p/view/home/kontakt/error500.shtml。我不懂德语,所以我很困惑。这是我尝试过的代码。你能说明我做错了什么吗?
<?php
$t=time();
$sig = md5('d06c00525957425b5719bba2c7a2c5a6'.$t);
$xml = simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?>
<AngebotssucheRequest xmlns="http://www.bahn.de/webservices/dritte/angebotssuche/request" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:db="http://www.bahn.de/webservices/dritte/datatypes/db">
<Header us="prabal" l="EN" t='.$t.' sig='.$sig.'/>
<RequestData d="8079732" s="8079706">
<DateTimeH d="822312689">
</DateTimeH>
</RequestData>
</AngebotssucheRequest>');
$header = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"run\"",
"Content-length: ".strlen($xml),
);
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, "https://fahrkartendritte.bahn.de/webservices/fahrkarten/v1" );
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $xml);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header);
if(curl_exec($soap_do) === false) {
$err = 'Curl error: ' . curl_error($soap_do);
curl_close($soap_do);
print $err;
} else {
$response = curl_exec($soap_do);
curl_close($soap_do);
$response1 = str_replace("<soap:Body>","",$response);
$response2 = str_replace("</soap:Body>","",$response1);
print_r($response);
print 'Operation completed without any errors';
}
?>
解决方案
推荐阅读
- python-3.x - 从阿拉伯语字符串中删除英文单词
- plpgsql - 为 plpgsql 函数返回复合类型时的意外行为
- apache-kafka - 如何为数据库事务实现 kafka 手动偏移提交
- html - 使用 CSS 居中内联块
- laravel - Laravel:为什么每条路线都执行两次?
- jquery - allowadditions 下拉菜单的语义 UI 设置值
- python - 如何在 Google Cloud Infrastructure 中通过电子邮件发送脚本结果(关于 Pub/Sub 和电子邮件及其他选项的设计查询)
- javascript - 从 Object.defineProperties() 定义的函数调用中获取“this”
- html - Bootstrap Multiselect - 冲突的CSS
- excel - 如何将数据从一个单元格复制到另一个单元格 - 取决于它旁边的单元格?