[英]How to fix file_get_contents warning
I am using following code in Google checkout gateway handler, but when I test it, it shows below warning: 我在Google Checkout网关处理程序中使用以下代码,但是在测试时,它显示以下警告:
Warning: file_get_contents(https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/XXXXXXXXXXX) [function.file-get-contents]: failed to open stream: HTTP request failed!
警告:file_get_contents(https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/XXXXXXXXXXX)[function.file-get-contents]:无法打开流:HTTP请求失败! HTTP/1.0 411 Length Required in /sample.php on line 116
第116行的/sample.php中要求的HTTP / 1.0 411长度
My line 116 looks like below: 我的行116如下所示:
//some more code//
$ctx = stream_context_create($params);
echo file_get_contents($_googleUrl, false, $ctx);
exit;
Can somebody help me here. 有人可以帮我吗?
411 Length Required
411所需长度
The server refuses to accept the request without a defined Content-Length.
服务器拒绝接受没有定义的Content-Length的请求。 The client may repeat the request if it adds a valid Content-Length header field containing the length of the entity body in the request message.
如果客户端在请求消息中添加了包含实体主体长度的有效Content-Length头字段,则客户端可以重复该请求。
This could mean that you are either not sending or sending an incorrect Content-Length
header in your request. 这可能意味着您没有在请求中发送或发送不正确的
Content-Length
标头。 Without knowing the contents of your $params
array it is difficult to debug this. 如果不知道
$params
数组的内容,则很难调试它。 So you will either need to get rid of the Content-Length
header if you are sending an incorrect one and let PHP handle it automatically (assuming PHP will do this) or if you are not currently sending it, send a correct one. 因此,如果您发送错误的
Content-Length
标头并让PHP自动处理它(假设PHP会这样做),或者您当前不发送它,则发送正确的标头。 As others have suggested, cURL may be a more viable option for doing this. 正如其他人所建议的那样,cURL可能是一个更可行的选择。
Also, doing a bit more research shows that some servers (mis)behave this way when you use POST, but do not provide any POST variables. 另外,进行更多的研究表明,当您使用POST时,某些服务器(错误)具有这种方式,但是不提供任何POST变量。 You can therefore solve this in one of two ways if this is the case.
因此,在这种情况下,您可以通过以下两种方法之一解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.