谁对http:// 0:port错了?

kob*_*ame 7 perl lwp psgi

Plack套件通常使用http://0:port.例如以下内容

plackup -MPlack::App::Directory -e 'Plack::App::Directory->new(root=>".");'
Run Code Online (Sandbox Code Playgroud)

版画

HTTP::Server::PSGI: Accepting connections at http://0:5000/
Run Code Online (Sandbox Code Playgroud)

但是,LWP::UserAgent(或一些更深层次的模块)不接受它,例如:

perl -MLWP::UserAgent -E '$u=LWP::UserAgent->new;$res=$u->get("http://0:5000/valid/path");print $res->status_line'
Run Code Online (Sandbox Code Playgroud)

打印:

500 No Host option provided
Run Code Online (Sandbox Code Playgroud)

但是

perl -MLWP::UserAgent -E '$u=LWP::UserAgent->new;$res=$u->get("http://localhost:5000/valid/path");print $res->status_line'
Run Code Online (Sandbox Code Playgroud)

版画

200 OK
Run Code Online (Sandbox Code Playgroud)

问题是:谁错了?

  • http://0:port有效的,例如LWP是"错误的"
  • 或者它无效,PSGI仅将其用作"随机有效"的快捷方式?

eck*_*kes 6

Plack套件的输出是服务器的输出.服务器通常bindš socket到特定端口和地址,以服务内容在那里.http://0:port在这种情况下,符号表示:本机的所有地址侦听端口port.如果您不知道或不想指定服务器应该可访问的机器的所有地址,这将非常方便.

LWP :: UserAgent的输出是客户端的输出.要打开与服务器的连接,必须显式指定要连接的地址端口.0没有有效的IP地址,因此当您连接失败连接http://0:port.

  • 答案是正确的,它应该包含:打印的URL无效.(和imho,使用`http://*:5000`会更清楚 - 但它不像0:5000`那样方便.:) :)反正:) (4认同)