如何从 Perl 发送 XML 到 CGI 程序?

发布于 2024-07-24 06:44:51 字数 227 浏览 5 评论 0原文

我想将一些 XML 从 Perl 程序发送到使用 XML::Simple 的 CGI 脚本 将该 XML 作为输入并发送 XML 作为输出。

有没有办法将 XML 从 Perl 发送到 CGI 脚本? 在这方面的任何帮助将非常感激。

谢谢

I want to send some XML from a Perl program to a CGI script that makes use of XML::Simple to take that XML as input and send XML as output.

Is there a way to send XML to a CGI script from Perl? Any help in this regards would be really appreciated.

Thank You

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

二智少女猫性小仙女 2024-07-31 06:44:53

假设您的程序中已经有 XML; 它只是一个 HTTP 请求,因此 LWP是你的朋友。 具体细节取决于 CGI 程序期望如何传递 XML(例如,POSTed url-encoded-form-data、多部分 MIME 等)

Assuming you have the XML in your program already; it is just an HTTP request, so LWP is your friend. The specifics depend on how the CGI program expects the XML to be passed (e.g. as POSTed url-encoded-form-data, multi-part MIME, etc)

哭了丶谁疼 2024-07-31 06:44:53

XML 没有什么特别之处:它只是文本。 像发送任何其他文本一样发送它。 还有其他不适合您的事情吗? 你已经尝试过什么?

如果您在向 CGI 程序发送任何内容时遇到问题,请查看诸如 WWW 之类的框架::Mechanize 为您完成请求和响应循环的大部分工作。

There's nothing special about XML: it's just text. Send it like you would send any other text. Is there something else that isn't working for you? What have you tried already?

If you're having trouble sending anything to the CGI program, take a look at a framework such as WWW::Mechanize which does most of the work of the request and response loop for you.

梦途 2024-07-31 06:44:52

可能的解决方案之一是使用 HTTP::Request::Common 模块,它公开了一些有用的函数,例如 GETPOSTHEADER

假设您想使用 POST 将数据发送到远程应用程序,您可以这样做:

use HTTP::Request::Common;
use LWP::UserAgent;

my $url = 'http://localhost/cgi-bin/mycgi.pl';
my $xml = "<root></root>";
my $request = POST $url, Content_Type => 'text/xml; charset=utf-8', Content => $xml;
my $ua = LWP::UserAgent->new();
my $response = $ua->request($request);
if ( $response->is_success() ) {
    print $response->content();
}
else {
    warn $response->status_line, $/;
}

希望这有帮助!

One of the possible solutions would be use the HTTP::Request::Common module, which exposes some useful functions like GET, POST and HEADER.

Assuming you want to use POST to send the data to the remote application, you could do:

use HTTP::Request::Common;
use LWP::UserAgent;

my $url = 'http://localhost/cgi-bin/mycgi.pl';
my $xml = "<root></root>";
my $request = POST $url, Content_Type => 'text/xml; charset=utf-8', Content => $xml;
my $ua = LWP::UserAgent->new();
my $response = $ua->request($request);
if ( $response->is_success() ) {
    print $response->content();
}
else {
    warn $response->status_line, $/;
}

Hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文