⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testrequest.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 3 页
字号:
cookies sent by the pages you are testing and send them back to theserver on subsequent requests. This is especially necessary whentesting pages whose functionality relies on sessions or the presenceof preferences stored in cookies.By default, C<LWP::UserAgent> does B<not> remember cookies betweenrequests. You can tell it to remember cookies between request byadding:  Apache::TestRequest::user_agent(cookie_jar => {});before issuing the requests.=head1 FUNCTIONSC<Apache::TestRequest> exports a number of functions that will likelyprove convenient for use in the majority of your request tests.=head2 Optional ParametersEach function also takes a number of optional arguments.=over 4=item redirect_okBy default a request will follow redirects retrieved from the server. Toprevent this behavior, pass a false value to a C<redirect_ok>parameter:  my $res = GET $uri, redirect_ok => 0;Alternately, if all of your tests need to disable redirects, tellC<Apache::TestRequest> to use an C<LWP::UserAgent> object thatdisables redirects:  Apache::TestRequest::user_agent( reset => 1,                                   requests_redirectable => 0 );=item certIf you need to force an SSL request to use a particular SSLcertificate, pass the name of the certificate via the C<cert>parameter:  my $res = GET $uri, cert => 'my_cert';=item contentIf you need to add content to your request, use the C<content>parameter:  my $res = GET $uri, content => 'hello world!';=item filenameThe name of a local file on the file system to be sent to the Apachetest server via C<UPLOAD()> and its friends.=back=head2 The Functions=head3 GET  my $res = GET $uri;Sends a simple GET request to the Apache test server. Returns anC<HTTP::Response> object.You can also supply additional headers to be sent with the request byadding their name/value pairs after the C<url> parameter, for example:  my $res = GET $url, 'Accept-Language' => 'de,en-us,en;q=0.5';=head3 GET_STRA shortcut function for C<GET($uri)-E<gt>as_string>.=head3 GET_BODYA shortcut function for C<GET($uri)-E<gt>content>.=head3 GET_BODY_ASSERTUse this function when your test is outputting content that you needto check, and you want to make sure that the request was successfulbefore comparing the contents of the request. If the request wasunsuccessful, C<GET_BODY_ASSERT> will return an errormessage. Otherwise it will simply return the content of the requestjust as C<GET_BODY> would.=head3 GET_OKA shortcut function for C<GET($uri)-E<gt>is_success>.=head3 GET_RCA shortcut function for C<GET($uri)-E<gt>code>.=head3 GET_HEADThrows out the content of the request, and returns the stringrepresentation of the request. Since the body has been thrown out, therepresentation will consist solely of the headers. Furthermore,C<GET_HEAD> inserts a "#" at the beginning of each line of the returnstring, so that the contents are suitable for printing to STDERRduring your tests without interfering with the workings ofC<Test::Harness>.=head3 HEAD  my $res = HEAD $uri;Sends a HEAD request to the Apache test server. Returns anC<HTTP::Response> object.=head3 HEAD_STRA shortcut function for C<HEAD($uri)-E<gt>as_string>.=head3 HEAD_BODYA shortcut function for C<HEAD($uri)-E<gt>content>. Of course, thismeans that it will likely return nothing.=head3 HEAD_BODY_ASSERTUse this function when your test is outputting content that you needto check, and you want to make sure that the request was successfulbefore comparing the contents of the request. If the request wasunsuccessful, C<HEAD_BODY_ASSERT> will return an errormessage. Otherwise it will simply return the content of the requestjust as C<HEAD_BODY> would.=head3 HEAD_OKA shortcut function for C<GET($uri)-E<gt>is_success>.=head3 HEAD_RCA shortcut function for C<GET($uri)-E<gt>code>.=head3 HEAD_HEADThrows out the content of the request, and returns the stringrepresentation of the request. Since the body has been thrown out, therepresentation will consist solely of the headers. Furthermore,C<GET_HEAD> inserts a "#" at the beginning of each line of the returnstring, so that the contents are suitable for printing to STDERRduring your tests without interfering with the workings ofC<Test::Harness>.=head3 PUT  my $res = PUT $uri;Sends a simple PUT request to the Apache test server. Returns anC<HTTP::Response> object.=head3 PUT_STRA shortcut function for C<PUT($uri)-E<gt>as_string>.=head3 PUT_BODYA shortcut function for C<PUT($uri)-E<gt>content>.=head3 PUT_BODY_ASSERTUse this function when your test is outputting content that you needto check, and you want to make sure that the request was successfulbefore comparing the contents of the request. If the request wasunsuccessful, C<PUT_BODY_ASSERT> will return an errormessage. Otherwise it will simply return the content of the requestjust as C<PUT_BODY> would.=head3 PUT_OKA shortcut function for C<PUT($uri)-E<gt>is_success>.=head3 PUT_RCA shortcut function for C<PUT($uri)-E<gt>code>.=head3 PUT_HEADThrows out the content of the request, and returns the stringrepresentation of the request. Since the body has been thrown out, therepresentation will consist solely of the headers. Furthermore,C<PUT_HEAD> inserts a "#" at the beginning of each line of the returnstring, so that the contents are suitable for printing to STDERRduring your tests without interfering with the workings ofC<Test::Harness>.=head3 POST  my $res = POST $uri, [ arg => $val, arg2 => $val ];Sends a POST request to the Apache test server and returns anC<HTTP::Response> object. An array reference of parameters passed asthe second argument will be submitted to the Apache test server as thePOST content. Parameters corresponding to those documented inL<Optional Parameters|/OptionalParameters> can follow the optional array reference of parameters, or afterC<$uri>.To upload a chunk of data, simply use:  my $res = POST $uri, content => $data;=head3 POST_STRA shortcut function for C<POST($uri, @args)-E<gt>content>.=head3 POST_BODYA shortcut function for C<POST($uri, @args)-E<gt>content>.=head3 POST_BODY_ASSERTUse this function when your test is outputting content that you needto check, and you want to make sure that the request was successfulbefore comparing the contents of the request. If the request wasunsuccessful, C<POST_BODY_ASSERT> will return an errormessage. Otherwise it will simply return the content of the requestjust as C<POST_BODY> would.=head3 POST_OKA shortcut function for C<POST($uri, @args)-E<gt>is_success>.=head3 POST_RCA shortcut function for C<POST($uri, @args)-E<gt>code>.=head3 POST_HEADThrows out the content of the request, and returns the stringrepresentation of the request. Since the body has been thrown out, therepresentation will consist solely of the headers. Furthermore,C<POST_HEAD> inserts a "#" at the beginning of each line of the returnstring, so that the contents are suitable for printing to STDERRduring your tests without interfering with the workings ofC<Test::Harness>.=head3 UPLOAD  my $res = UPLOAD $uri, \@args, filename => $filename;Sends a request to the Apache test server that includes an uploadedfile. Other POST parameters can be passed as a second argument as anarray reference.C<Apache::TestRequest> will read in the contents of the file named viathe C<filename> parameter for submission to the server. If you'drather, you can submit use the C<content> parameter instead ofC<filename>, and its value will be submitted to the Apache server asfile contents:  my $res = UPLOAD $uri, undef, content => "This is file content";The name of the file sent to the server will simply be "b". Note thatin this case, you cannot pass other POST arguments to C<UPLOAD()> --they would be ignored.=head3 UPLOAD_BODYA shortcut function for C<UPLOAD($uri, @params)-E<gt>content>.=head3 UPLOAD_BODY_ASSERTUse this function when your test is outputting content that you needto check, and you want to make sure that the request was successfulbefore comparing the contents of the request. If the request wasunsuccessful, C<UPLOAD_BODY_ASSERT> will return an errormessage. Otherwise it will simply return the content of the requestjust as C<UPLOAD_BODY> would.=head3 OPTIONS  my $res = OPTIONS $uri;Sends an C<OPTIONS> request to the Apache test server. Returns anC<HTTP::Response> object with the I<Allow> header, indicating whichmethods the server supports. Possible methods include C<OPTIONS>,C<GET>, C<HEAD> and C<POST>. This function thus can be useful fortesting what options the Apache server supports. Consult the HTTPD 1.1specification, section 9.2, atI<http://www.faqs.org/rfcs/rfc2616.html> for more information.=head2 URL Manipulation FunctionsC<Apache::TestRequest> also includes a few helper functions to aid inthe creation of urls used in the functions above.=head3 C<module2path>  $path = Apache::TestRequest::module2path($module_name);Convert a module name to a path, safe for use in the various requestmethods above. e.g. C<::> can't be used in URLs on win32. For example:  $path = Apache::TestRequest::module2path('Foo::Bar');returns:  /Foo__Bar=head3 C<module2url>  $url = Apache::TestRequest::module2url($module);  $url = Apache::TestRequest::module2url($module, \%options);Convert a module name to a full URL including the currentconfigurations C<hostname:port> and sets C<module> accordingly.  $url = Apache::TestRequest::module2url('Foo::Bar');returns:  http://$hostname:$port/Foo__BarThe default scheme used is C<http>. You can override this by passingyour preferred scheme into an optional second param. For example:  $module = 'MyTestModule::TestHandler';  $url = Apache::TestRequest::module2url($module, {scheme => 'https'});returns:  https://$hostname:$port/MyTestModule__TestHandlerYou may also override the default path with a path of your own:  $module = 'MyTestModule::TestHandler';  $url = Apache::TestRequest::module2url($module, {path => '/foo'});returns:  http://$hostname:$port/foo=head1 ENVIRONMENT VARIABLESThe following environment variables can affect the behavior ofC<Apache::TestRequest>:=over=item APACHE_TEST_PRETEND_NO_LWPIf the environment variable C<APACHE_TEST_PRETEND_NO_LWP> is set to atrue value, C<Apache::TestRequest> will pretend that LWP is notavailable so one can test whether the test suite will survive on asystem which doesn't have libwww-perl installed.=item APACHE_TEST_HTTP_09_OKIf the environment variable C<APACHE_TEST_HTTP_09_OK> is set to atrue value, C<Apache::TestRequest> will allow HTTP/0.9 responsesfrom the server to proceed.  The default behavior is to die ifthe response protocol is not either HTTP/1.0 or HTTP/1.1.=back=head1 SEE ALSOL<Apache::Test|Apache::Test> is the main Apache testing module. Use itto set up your tests, create a plan, and to ensure that you have theApache version and modules you need.Use L<Apache::TestMM|Apache::TestMM> in your I<Makefile.PL> to set upyour distribution for testing.=head1 AUTHORDoug MacEachern with contributions from Geoffrey Young, PhilippeM. Chiasson, Stas Bekman and others. Documentation by David Wheeler.Questions can be asked at the test-dev <at> httpd.apache.org list. Formore information see: I<http://httpd.apache.org/test/> andI<http://perl.apache.org/docs/general/testing/testing.html>.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -