Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7802965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:25:08+00:00 2026-06-02T01:25:08+00:00

I have written this code to fire a http request through a proxy. But

  • 0

I have written this code to fire a http request through a proxy.
But the request does not seem to use proxy. Even though I give a wrong proxy, it is returning OK.

Is there any way I can check, whether the HTTP request went via proxy?
What is the issue in this code which makes it not use proxy?

sub fire_http_request_through_proxy()
{
    my $proxy = $_;
    my $ua = LWP::UserAgent->new;
    $ENV{HTTP_PROXY} = $proxy;
    $ua->env_proxy; # initialize from environment variables
    $ua->timeout(20);
    my $response = $ua->get('http://www.google.com');
    delete $ENV{HTTP_PROXY};
    if ($response->is_success)
    {
       print $response->decoded_content . "\n";
    }
    else
    {
       die $response->status_line;
    }  
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:25:11+00:00Added an answer on June 2, 2026 at 1:25 am

    Are you sure that $_ has a true value? This dies appropriately for me:

    #!/usr/bin/env perl
    
    use strict;
    use warnings;
    use LWP::UserAgent;
    
    fire_http_request_through_proxy();
    
    sub fire_http_request_through_proxy {
        my $ua = LWP::UserAgent->new;
        local $ENV{HTTP_PROXY} = 'http://1.1.1.1';
        $ua->env_proxy;    # initialize from environment variables
        $ua->timeout( 20 );
        my $response = $ua->get( 'http://www.google.com' );
        delete $ENV{HTTP_PROXY};
        if ( $response->is_success ) { 
            print $response->decoded_content . "\n";
        }   
        else {
            die $response->status_line;
        }   
    } 
    

    So, maybe $_ isn’t what you think it is. If it’s not defined, then no proxy will be used. Having said that, $_ is probably not the variable you want to use here. You could either declare a variable for use in this case, pass a variable right to the subroutine or actually set an ENV variable outside of the script.

    One other point. Rather than setting and deleting the ENV var in your script, just declare the change with local and it will only take effect inside this block of code. That way you don’t have to clean up after yourself and you don’t risk overriding vars which may have been set elsewhere.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my code I have written this but it fails to compile: In Class1.h:
I have written this code that loops through an array of lat/long coordinates and
I have written this code but it will print these stack traces in the
I have written this code but it doesn't compute ((((bY - aY) / (maxX
i have written this code and its not working...... indate = 13/1/2011 Calendar cd1
I have written this code to loop through the last 6 posts and display
So I have written this code for getting AlarmManager to fire on a specified
I have written this code to join ArrayList elements: Can it be optimized more?
I have written this code to convert string in such format 0(532) 222 22
I have written this code in javascript however I have to make it work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.