开发者

kohana 3.1 Request External: POST application/xml doesn't work with native execute

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 work开发者_StackOverflow中文版s. Is these two errors are bugs or am I doing something wrong?


It's a bug and has been fixed in the 3.1/develop branch. It'll be released on the next point release (soon).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜