Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何修复文件内容和expedia XML API的411长度要求错误?_Php_Xml_Api_Http - Fatal编程技术网

Php 如何修复文件内容和expedia XML API的411长度要求错误?

Php 如何修复文件内容和expedia XML API的411长度要求错误?,php,xml,api,http,Php,Xml,Api,Http,我正在使用XMLAPI(php)项目进行在线酒店预订 “警告:文件获取内容”(https://...@gmail.comtestsmith8870606867CA5401999999999999…[函数.文件获取内容]:无法打开流:HTTP请求失败!需要HTTP/1.0 411长度“ 这是我的密码 $context = stream_context_create( array( 'http' => array(

我正在使用XMLAPI(php)项目进行在线酒店预订

“警告:文件获取内容”(https://...@gmail.comtestsmith8870606867CA5401999999999999…[函数.文件获取内容]:无法打开流:HTTP请求失败!需要HTTP/1.0 411长度“

这是我的密码

$context  = stream_context_create(
                array(
                    'http' => array(
                        'method' => 'POST',
                        'header' => "Content-type: application/x-www-form-urlencoded",
                        "Accept: application/xml"
                    )
                )
            );
$url ='https://book.api.ean.com/....';
$xml = file_get_contents($url, false, $context);
这是发送信用信息请给我建议什么类型的错误

根据:

您需要将
Content Length
标题添加到
POST
请求中。这是POST请求正文的字节(八位字节)大小。要获得长度,可以在帖子正文上使用
strlen
。由于您的代码示例没有显示任何帖子正文,因此很难给出具体的示例。在流上下文中,通过
['http']['content']
项传递帖子正文

如果您设置了(请参阅),可能已经足够了

编辑:以下示例代码可能会解决您的问题。它演示了如何使用
file\u get\u contents
和设置包括
Content Length
头的头,通过POST请求向服务器发送一些XML

$url = 'https://api.example.com/action';
$requestXML = '<xml><!-- ... the xml you want to post to the server... --></xml>';
$requestHeaders = array(
    'Content-type: application/x-www-form-urlencoded',
    'Accept: application/xml',
    sprintf('Content-Length: %d', strlen($requestXML));
);

$context = stream_context_create(
                array(
                    'http' => array(
                        'method'  => 'POST',
                        'header'  => implode("\r\n", $requestHeaders),
                        'content' => $requestXML,
                    )
                )
            );
$responseXML = file_get_contents($url, false, $context);

if (FALSE === $responseXML)
{
    throw new RuntimeException('HTTP request failed.');
}
$url='1!'https://api.example.com/action';
$requestXML='';
$requestHeaders=数组(
'内容类型:application/x-www-form-urlencoded',
“接受:应用程序/xml”,
sprintf('Content-Length:%d',strlen($requestXML));
);
$context=stream\u context\u create(
排列(
“http'=>数组(
'方法'=>'发布',
'header'=>内爆(“\r\n”,$requestHeaders),
'content'=>$requestXML,
)
)
);
$responseXML=file\u get\u contents($url,false,$context);
if(FALSE==$responseXML)
{
抛出新的RuntimeException('HTTP请求失败');
}
如果需要更好的错误控制,请参阅和。有关HTTP响应头的详细处理,请参见我的一篇博文:.

,具体内容如下:

您需要将
Content Length
标题添加到
POST
请求中。这是POST请求正文的字节(八位字节)大小。要获得长度,可以在帖子正文上使用
strlen
。由于您的代码示例没有显示任何帖子正文,因此很难给出具体的示例。在流上下文中,通过
['http']['content']
项传递帖子正文

如果您设置了(请参阅),可能已经足够了

编辑:以下示例代码可能会解决您的问题。它演示了如何使用
file\u get\u contents
和设置包括
Content Length
头的头,通过POST请求向服务器发送一些XML

$url = 'https://api.example.com/action';
$requestXML = '<xml><!-- ... the xml you want to post to the server... --></xml>';
$requestHeaders = array(
    'Content-type: application/x-www-form-urlencoded',
    'Accept: application/xml',
    sprintf('Content-Length: %d', strlen($requestXML));
);

$context = stream_context_create(
                array(
                    'http' => array(
                        'method'  => 'POST',
                        'header'  => implode("\r\n", $requestHeaders),
                        'content' => $requestXML,
                    )
                )
            );
$responseXML = file_get_contents($url, false, $context);

if (FALSE === $responseXML)
{
    throw new RuntimeException('HTTP request failed.');
}
$url='1!'https://api.example.com/action';
$requestXML='';
$requestHeaders=数组(
'内容类型:application/x-www-form-urlencoded',
“接受:应用程序/xml”,
sprintf('Content-Length:%d',strlen($requestXML));
);
$context=stream\u context\u create(
排列(
“http'=>数组(
'方法'=>'发布',
'header'=>内爆(“\r\n”,$requestHeaders),
'content'=>$requestXML,
)
)
);
$responseXML=file\u get\u contents($url,false,$context);
if(FALSE==$responseXML)
{
抛出新的RuntimeException('HTTP请求失败');
}

如果需要更好的错误控制,请参阅和。HTTP响应头的详细处理可在我的一篇博客文章中找到:。

您在设置流上下文选项的方式上有一个错误。谢谢plz更正我的代码提前谢谢StackOverflow不允许发布代码。我已经提供了足够的代码您在设置流上下文选项的方式上有一个错误。谢谢plz更正我的代码谢谢advancestackoverflow不允许发布代码。我已经为我的代码plz帮助提供了足够的代码如何做内容长度me@user1117625:您需要更改代码,它不完整,我无法执行,因此无法复制。对不起,你读过哈克雷写的东西吗<代码>内容长度被提到了两次(为了您的缘故,甚至还加了颜色)。不需要天才就能知道该做什么,把它放在哪里。现在人们真的没有努力找出解决方案吗?$url='$str=strlen($url)$context=stream\u context\u create(数组('http'=>array('method'=>'POST','header'=>“Content type:application/x-www-form-urlencoded”,“Accept:application/xml”,“Content-Length:$str”));我的代码是否正确检查代码是否正确?流式上下文创建(数组('http'=>array('method'=>'POST','header'=>“Content type:application/x-www-form-urlencoded”,“Accept:application/xml”,“Content-Length:$str”);如何为我的代码设置内容长度plz帮助me@user1117625:您需要更改代码,它不完整,我无法执行,因此无法复制。对不起,你读过哈克雷写的东西吗<代码>内容长度被提到了两次(为了您的缘故,甚至还加了颜色)。不需要天才就能知道该做什么,把它放在哪里。现在人们真的没有努力找出解决方案吗?$url='$str=strlen($url)$context=stream\u context\u create(数组('http'=>array('method'=>'POST','header'=>“Content type:application/x-www-form-urlencoded”,“Accept:application/xml”,“Content-Length:$str”));我的代码是否正确检查代码是否正确?流式上下文创建(数组('http'=>array('method'=>'POST','header'=>“Content type:application/x-www-form-urlencoded”,“Accept:application/xml”,“Content-Length:$str”);