[英]how to send a http patch request with Lwp::Useragent?
我正在使用lwp :: useragent來反對salesforce rest api。
我必須使用http補丁請求。
對於get和post請求,我們使用以下代碼:
需要LWP :: UserAgent;
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
my $get_response = $ua->get('http://search.cpan.org/',x=>'y');
my $post_response = $ua->post('http://search.cpan.org/',x=>'y');
不幸的是,這不起作用
my $patch_response = $ua->patch('http://search.cpan.org/',x=>'y');
我沒有找到如何使用此模塊。
這個問題有一個解決方法,如此處所述, 如何使用PATCH方法為Salesforce更新發送請求?
這可行,但這不是一個很好的解決方案。
我看到使用python可以顯式修補請求如何在Python中創建PATCH請求? 所以我假設perl也有一個選項。
my $request = HTTP::Request->new(PATCH => $url);
... Add any necessary headers and body ...
my $response = $ua->request($request);
這最近變得更容易了。 PATCH
現在在HTTP::Message
實現(如POST
)。
首先,更新HTTP::Message
模塊(到6.13或更高版本)。
然后
my %fields = ( title => 'something', body => something else');
my $ua = LWP::UserAgent->new();
my $request = HTTP::Request::Common::PATCH( $url, [ %fields ] );
my $response = $ua->request($request);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.