我正试图用Kohana 3.1在我的控制器中执行一个外部请求。
$request = Request::factory($url);
$request->method(Request::POST);
$request->body($xml);
$request->headers('Content-Type', 'application/xml');
$response = $request->execute();
我得到这个错误:
HTTP_Exception_500 [ 500 ]: Kohana_HTTP_Header_Value::__construct unknown header value type: integer. array or string allowed.
经过对代码的一些研究,我发现这是类Kohana_Request_Client_External
的函数_native_execute
的问题。
此函数设置"内容长度",如下所示:
$body = $request->body();
$request->headers('content-length', strlen($body));
但是$request->header(...)
期望第二个参数为字符串或数组,而strlen
返回一个整数。
是虫子吗?我像这个$request->headers('content-length', (string)strlen($body));
一样修复了它
然后我得到了另一个错误:
ErrorException [ Warning ]: fopen(http://xxx.xxx.xxx.xxx/yyyyy) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: HTTP wrapper does not support writeable connections
此错误再次来自_native_execute
中的这行代码$mode = ($request->method() === HTTP_Request::GET) ? 'r' : 'r+';
。
我强迫$mode
的值为r
,现在它工作了。这两个错误是错误还是我做错了什么?
这是一个错误,已在3.1/develop分支中修复。它将在下一次发布时发布(很快)。