简体   繁体   English

perl lwp表格发布

[英]perl lwp form post

I'm trying to use LWP to post some content to a hosted service, over which I have no control, ie I must conform to their standards. 我正在尝试使用LWP将某些内容发布到托管服务,但我无法控制该托管服务,即我必须遵守其标准。

Basically, the content must go over in a post which looks similar to the following: 基本上,内容必须在类似于以下内容的帖子中进行浏览:

POST / HTTP/1.1
Accept:*/*
Content-Type: text/xml
[various other headers]

<?xml version="1.0" encoding="UTF-8"?>
<xmlContent>here</xmlContent>

I'm looking at the LWP documentation, and its example looks like this: 我正在查看LWP文档,其示例如下所示:

$response = $browser->post( $url,
   ['form' => '<?xml version="1.0" encoding="UTF-8"?><content>foobarbaz</content>'],
   'Content_Type' => 'text/xml', 
   'headerkey2' => 'hvalue2', 
 );

so instead, my data is going over like this: 所以相反,我的数据像这样遍历:

[headers]

form=<?xml blah blah blah

I don't want the "form=" in there. 我不要在那儿“ form =“。

I've tried a few work-arounds, but I either end up with nothing getting sent, or with an extra '=' sign at the end. 我已经尝试了一些解决方法,但最终还是没有得到任何发送,或者最后没有额外的“ =”符号。 It seems like this should be easy... is there any way I can get my content to go as the body of the post WITHOUT the variable name? 似乎这应该很容易...有什么方法可以让我的内容成为帖子的主体而没有变量名?

I'm open to doing things other than using LWP, that was just my jumping off point because I've used it before. 除了使用LWP,我愿意做其他事情,这只是我的出发点,因为我以前使用过它。

Thanks! 谢谢!

I don't think you need a FORM: 我认为您不需要表格:

  $req = HTTP::Request->new(POST => $url);
  $req->header("Content-Type" => "text/xml");
  $req->content(<<EOT);
  <?xml version="1.0" encoding="UTF-8"?>
  <xmlContent>here</xmlContent>
  EOT

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM