我在这里尝试了这段代码来共享我所在的当前页面,但是一些url是关闭的,所以它共享了错误的页面。我计算出符号"&“被剪掉了,所以我想知道是否有人知道如何绕过它。
代码:
<a target="_blank" href="http://www.facebook.com/sharer/sharer.php?u=http://www.ibidthai.com/auction.pl?category=$form{'category'}&item=$form{'item'}">Share</a>$form{'category'}和$form{'item'}是一个变量,在本例中是它的category="car“和item="[]1415689774”
发布于 2014-10-14 00:34:29
您需要使用URI::Escape或一些类似的模块/功能来转义查询参数:
use strict;
use warnings;
use URI::Escape;
my %form = ( category => 'car', item => '[]1415689774' );
my $u = "http://www.ibidthai.com/auction.pl?category=$form{'category'}&item=$form{'item'}";
my $url = "http://www.facebook.com/sharer/sharer.php?u=" . uri_escape($u);
print "$url\n";输出:
http://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fwww.ibidthai.com%2Fauction.pl%3Fcategory%3Dcar%26item%3D%5B%5D1415689774但是,如果您想要彻底,如果第一个URI的查询参数可能包含特殊字符,则两个URI实际上都应该进行编码:
use strict;
use warnings;
use URI;
my %form = ( category => 'car', item => '[]1415689774' );
my $auction_uri = URI->new("http://www.ibidthai.com/auction.pl");
$auction_uri->query_form( category => $form{category}, item => $form{item} );
print "$auction_uri\n";
my $share_uri = URI->new('http://www.facebook.com/sharer/sharer.php');
$share_uri->query_form( u => "$auction_uri" );
print "$share_uri\n";输出:
http://www.ibidthai.com/auction.pl?category=car&item=%5B%5D1415689774
http://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fwww.ibidthai.com%2Fauction.pl%3Fcategory%3Dcar%26item%3D%255B%255D1415689774https://stackoverflow.com/questions/26336965
复制相似问题