سؤال

وأنا لا أريد أن استخدام حزمة HTTP :: وكيل لأنني أريد أن تفريغ يطلب أحد الزوجين. بلدي بطانة واحدة تبدو مثل هذا، ولكن فواصل على محاولة تمرير رأس في:

perl -MData::Dumper -MHTTP::Daemon -MHTTP::Status -MLWP::UserAgent -e 'my $ua = LWP::UserAgent->new;my $d=new HTTP::Daemon(LocalPort=>1999);print "Please contact me at: <", $d->url, ">\n";while (my $c = $d->accept) {while (my $r = $c->get_request) {if ($r->method eq 'GET' and $r->url->path eq "/uploader") {$c->send_response("whatever.");print Dumper($r);}else{$response=$ua->request($r->method,"http://localhost:1996".$r->uri,$r->headers,$r->content);$c->send_response($response);}}}'

وتنسيقها، وهذا هو:

#perl -e '
use Data::Dumper;
use HTTP::Daemon;
use HTTP::Status;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my $d=new HTTP::Daemon(LocalPort=>1999);
print "Please contact me at: < ", $d->url, " >\n";
while (my $c = $d->accept) {
  while (my $r = $c->get_request) {
    if ($r->method eq 'GET' and $r->url->path eq "/uploaded") {
      $c->send_response("whatever.");
      print Dumper($r);
    } else { 
      $response = $ua -> request(
        $r->method, 
        "http://localhost:1996" . $r->uri, 
        $r->headers, 
        $r->content);
      $c->send_response($response);
    }
  }
}#'

وهكذا لا أستطيع أن يمر في الطلب، لأنني بحاجة إلى تغيير البلد المضيف، وأنا لا يمكن أن يمر في رؤوس يبدو ... لذلك ما يجب أن أفعل ليبقيه قصيرة.

وهكذا يمكن لأي شخص جعل هذا أفضل الخطوط الملاحية المنتظمة واحد؟

هل كانت مفيدة؟

المحلول

وفصيل عبد الواحد تبادل لاطلاق النار، وأنها ثابتة مع هذا:

#perl -e '
use Data::Dumper;
use HTTP::Daemon;
use HTTP::Status;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my $d=new HTTP::Daemon(LocalPort=>1999);
print "Please contact me at: < ", $d->url, " >\n";
while (my $c = $d->accept) {
  while (my $r = $c->get_request) {
    if ($r->method eq "GET" and $r->url->path eq "/uploaded") {
      $c->send_response("whatever.");
      print Dumper($r);
    } else { 
      $response = $ua -> request( HTTP::Request->new(
        $r->method, 
        "http://localhost:1996" . $r->uri, 
        $r->headers, 
        $r->content));
      $c->send_response($response);
    }
  }
}#'

لاحظ HTTP::Request->new نعم ... لذلك يعمل، انها صبي بطيئة. لكن هذا ما يرام

نصائح أخرى

لماذا نحاول جاهدين لكتابة الخطوط الملاحية المنتظمة واحد؟ هناك سبب لا يمكنك حفظ البرنامج في الملف؟ أنا مجرد لافتة ما هو الوضع.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top