如何在没有LWP :: UserAgent或HTTP :: Request的情况下在Perl中发送HTTPS请求?(How can I send an HTTPS request in Perl without LWP::UserAgent or HTTP::Request?)

其他开发 IT屋
百度翻译此文   有道翻译此文
问 题

I need to send an HTTPS request without using LWP::UserAgent or HTTP::request? What is another method of doing so? This is the request I need to send:

POST https://payflowpro.paypal.com/
Connection: close
Host: payflowpro.paypal.com
Content-Length: 181
Content-Type: text/namevalue
X-VPS-CLIENT-TIMEOUT: 30
X-VPS-REQUEST-ID: 1249403513SNOID
X-VPS-VIT-INTEGRATION-PRODUCT: Product
X-VPS-VIT-INTEGRATION-VERSION: 4.0
X-VPS-VIT-OS-NAME: linux
X-VPS-VIT-OS-VERSION: 2.6.16-gentoo-r13
X-VPS-VIT-RUNTIME-VERSION: 5.008007

EXPDATE[4]=1011&AMT[6]=100.01&ACCT[16]=4111111111111111&TENDER[1]=C&TAXAMT[4]=0.00&PARTNER[8]=******&PWD[9]=******&VENDOR[6]=******&USER[6]=******&TRXTYPE[1]=S&VERBOSITY=MEDIUM
解决方案

Thanks to package reference by Sinan Ünür I was able to accomplish what I needed:

my $host = 'pilot-payflowpro.paypal.com';
my $port = 443;
my $sock = IO::Socket::SSL->new("$host:$port") || die $!;

my $req = 'EXPDATE[4]=1011&AMT[6]=100.01&ACCT[16]=4111111111111111&TENDER[1]=C&TAXAMT[4]=0.00&PARTNER[8]=*****&PWD[9]=******&VENDOR[6]=*****&USER[6]=******&TRXTYPE[1]=S&VERBOSITY=MEDIUM';

print $sock "POST https://$host/ HTTPS/1.1\r\n";
print $sock "Connection: close", "\r\n";
print $sock "Host: ", $host, "\r\n";
print $sock "Content-length: ", length $req, "\r\n";
print $sock "Content-type: text/namevalue\r\n";
print $sock "X-VPS-CLIENT-TIMEOUT: 30", "\r\n";
print $sock "X-VPS-REQUEST-ID: 1249403513SNOID", "\r\n";
print $sock "X-VPS-VIT-INTEGRATION-PRODUCT: Product", "\r\n";
print $sock "X-VPS-VIT-INTEGRATION-VERSION: 4.0", "\r\n";
print $sock "X-VPS-VIT-OS-NAME: linux", "\r\n";
print $sock "X-VPS-VIT-OS-VERSION: 2.6.16-gentoo-r13", "\r\n";
print $sock "X-VPS-VIT-RUNTIME-VERSION: 5.008007", "\r\n\r\n";
print $sock $req, "\r\n\r\n";

print while <$sock>;

close $sock;

本文地址:IT屋 » How can I send an HTTPS request in Perl without LWP::UserAgent or HTTP::Request?

问 题

我需要在不使用LWP :: UserAgent或HTTP :: request的情况下发送HTTPS请求吗?这样做的另一种方法是什么?这是我需要发送的请求:



  POST https://payflowpro.paypal.com/ 
连接:关闭
主持人:payflowpro.paypal.com
内容长度:181
内容类型:text / namevalue
X-VPS-CLIENT-TIMEOUT:30
X -VPS-REQUEST-ID:1249403513SNOID
X-VPS-VIT-INTEGRATION-PRODUCT:产品
X-VPS-VIT-INTEGRATION-VERSION:4.0
X-VPS-VIT-OS-名称:linux
X-VPS-VIT-OS-VERSION:2.6.16-gentoo-r13
X-VPS-VIT-RUNTIME-VERSION:5.008007

EXPDATE [4 ] = 1011&安培; AMT [6] = 100.01&安培; ACCT [16] = 4111111111111111&安培;嫩[1] = C&安培; TAXAMT [4] = 0.00&安培; PARTNER [8] = ******&安培; PWD [9 ] = ******& VENDOR [6] = ******& USER [6] = ******& TRXTYPE [1] = S& VERBOSITY = MEDIUM

解决方案

感谢SinanÜnür的包装参考我能够完成我需要的工作:



  my $ host ='pilot-payflowpro.paypal.com'; 
my $ port = 443;
my $ sock = IO :: Socket :: SSL-> new(“$ host:$ port”)||死!$ ;;

我的$ req ='EXPDATE [4] = 1011& AMT [6] = 100.01& ACCT [16] = 4111111111111111& TENDER [1] = C& TAXAMT [4] = 0.00& PARTNER [8] = *****&安培; PWD [9] = ******&安培; VENDOR [6] =&*****放大器; USER [6] =&******放大器; TRXTYPE [1] = S&安培; VERBOSITY = MEDIUM';

print $ sock“POST https:// $ host / HTTPS / 1.1\\ n”;
print $ sock“Connection:close”,“\\\\ n”;
print $ sock“Host:”,$ host,“\\\\ n”;
print $ sock“Content-length:”,length $ req,“\\\\ n”;
print $ sock“Content-type:text / namevalue\r\ n”;
print $ sock“X-VPS-CLIENT-TIMEOUT:30”,“\\\\ n”;
print $ sock“X-VPS-REQUEST-ID:1249403513SNOID”,“\\ n”;
print $ sock“X-VPS-VIT-INTEGRATION-PRODUCT:Product”,“\\ n”;
print $ sock“X-VPS-VIT-INTEGRATION-VERSION:VERSION:4.0”,“\\\\ n”;
print $ sock“X-VPS-VIT-OS-NAME:linux”,“\\\\ n”;
print $ sock“X-VPS-VIT-OS-VERSION:2.6.16-gentoo-r13”,“\\\\ n”;
print $ sock“X-VPS-VIT-RUNTIME-VERSION:5.008007”,“\\\\\\\ n”;
print $ sock $ req,“\\\\\\\ n”;

打印时< $ sock> ;;

关闭$ sock;

本文地址:IT屋 » 如何在没有LWP :: UserAgent或HTTP :: Request的情况下在Perl中发送HTTPS请求?

官方微信
扫一扫关注IT屋
微信公众号搜索 “ IT屋 ” ,选择关注
与百万开发者在一起