2017-02-04 73 views
4

創建$tx對象爲:爲什麼我不能用Mojo :: UserAgent重複請求?

my $tx = $self->ua->build_tx($method, ...); 

然後請求:

my $res = $self->ua->start($tx)->res; 

我得到了正確的反應,但是當我想重申的要求,我得到錯誤:

my $repeat = $self->ua->start($tx)->res; 
Can't call method "stream" on an undefined value at /local/lib/perl5/Mojo/UserAgent.pm line 155. 

爲什麼我無法重複請求?

+0

只是猜測,你可能需要新的'$ tx'對象。 http://mojolicious.org/perldoc/Mojo/Transaction#is_finished –

回答

2

Mojo ua tx不可重用,因此創建一個新的。

+0

我最好建立'req'對象,然後把它放到'tx'中,並根據需要重用'req'。查看代碼'build_tx'可以使用'req',所以最好將它命名爲'build_req' ...它會更方便 –

相關問題