kohana 3.1 外部请求:POST application/xml 不适用于本机执行
我正在尝试使用 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
此错误来自这行代码 <代码>$mode = ($request->method() === HTTP_Request::GET) ? 'r' : 'r+'; 再次在 _native_execute
中。
我强制将 $mode
的值设置为 r
,现在它可以工作了。这两个错误是错误还是我做错了什么?
I'm trying to perform an external request with Kohana 3.1 with this code in my controller.
$request = Request::factory($url);
$request->method(Request::POST);
$request->body($xml);
$request->headers('Content-Type', 'application/xml');
$response = $request->execute();
I'm getting this error:
HTTP_Exception_500 [ 500 ]: Kohana_HTTP_Header_Value::__construct unknown header value type: integer. array or string allowed.
After some research in the code, I found out this was a problem with the function _native_execute
of the class Kohana_Request_Client_External
.
This function sets 'content-length' like so:
$body = $request->body();
$request->headers('content-length', strlen($body));
But $request->header(...)
expect a string or an array for the second parameter and strlen
returns an integer.
Is it a bug? I fixed it like this $request->headers('content-length', (string)strlen($body));
Then I got another error:
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
This error comes from this line of code $mode = ($request->method() === HTTP_Request::GET) ? 'r' : 'r+';
again in _native_execute
.
I forced the value of $mode
to be r
and now it works. Is these two errors are bugs or am I doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个错误,已在 3.1/develop 分支中修复。它将在下一个版本(很快)中发布。
It's a bug and has been fixed in the 3.1/develop branch. It'll be released on the next point release (soon).