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 8096427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:26:50+00:00 2026-06-05T21:26:50+00:00

I am working on a uploader class which will use the system’s proxy settings

  • 0

I am working on a uploader class which will use the system’s proxy settings to upload the files. In IE, if i enable the proxy settings, upload is not happening. Its stucked at the following line

 System.out.println("Now uploading your file into bayfiles.com");
            HttpResponse response = httpclient.execute(httppost);

If i disable the proxy settings, then file is successfully uploaded. I dont know hat is the reason. Can anybody explain me why this happening?

Then one more doubt. Though upload is working if i disable the proxy settings, login to the site is not working. Is there anything wrong in the code? Correct me if I am wrong,

Thanks.

My code is as follows,

public class BayFilesUploaderPlugin {

    private static URL u;
    private static HttpURLConnection uc;
    private static BufferedReader br;
    private static String tmp;
    private static String postURL;
    private static File file;
    private static String uploadresponse;
    private static String downloadlink;
    private static String deletelink;
    private static String sessioncookie;
    private static boolean login = false;
    private static String proxy_address;
    private static String proxy_host = "myproxy.mydomain.com";
    private static String proxy_port = "8080";

    public static void main(String[] args) throws Exception {

//        java.net.ProxySelector.setDefault(new MyProxySelector(ProxySelector.getDefault()));
        System.setProperty("java.net.useSystemProxies", "true");
//        Proxy next = ProxySelector.getDefault().select(new URI("http://www.google.com/")).iterator().next();
//
//        if (next.address() != null) {
//            proxy_address = next.address().toString();
//            proxy_host = proxy_address.substring(0, proxy_address.indexOf(":"));
//            proxy_port = proxy_address.substring(proxy_address.indexOf(":") + 1);
//
//            System.out.println("Host : " + proxy_host);
//            System.out.println("Port : " + proxy_port);
//            System.setProperty("https.proxyHost", proxy_host);
//            System.setProperty("http.proxyHost", proxy_host);
//            System.setProperty("https.proxyPort", proxy_port);
//            System.setProperty("http.proxyPort", proxy_port);
//        }




        // 

        System.setProperty("https.proxyHost", proxy_host);
        System.setProperty("http.proxyHost", proxy_host);
        System.setProperty("https.proxyPort", proxy_port);
        System.setProperty("http.proxyPort", proxy_port);

        initialize();
//        loginBayFiles();
//        System.exit(0);
        fileUpload();


    }

    private static void initialize() throws Exception {
        System.out.println("Getting upload url from bayfiles.com");
        System.setProperty("java.net.useSystemProxies", "true");
        u = new URL("http://bayfiles.com/ajax_upload?_=" + new Date().getTime());
        uc = (HttpURLConnection) u.openConnection();
        if (login) {
            uc.setRequestProperty("Cookie", sessioncookie);
        }
        br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
        String k = "";
        while ((tmp = br.readLine()) != null) {
            k += tmp;
        }
        postURL = parseResponse(k, "\"upload_url\":\"", "\"");
        postURL = postURL.replaceAll("\\\\", "");
        System.out.println("Post URL : " + postURL);
    }

    public static String parseResponse(String response, String stringStart, String stringEnd) {

        response = response.substring(response.indexOf(stringStart));
        response = response.replace(stringStart, "");
        response = response.substring(0, response.indexOf(stringEnd));
        return response;
    }

    private static void fileUpload() throws Exception {

        DefaultHttpClient httpclient = new DefaultHttpClient();

//        httpclient.getCredentialsProvider().setCredentials(
//                new AuthScope("myproxy.mydomain.com", 80),
//                new UsernamePasswordCredentials("", ""));

        //    HttpHost targetHost = new HttpHost("www.verisign.com", 443, "https");
        HttpHost proxy = new HttpHost("myproxy.mydomain.com", 80);

        httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);


        HttpPost httppost = new HttpPost(postURL);
        file = new File("C:\\Dinesh\\naruto.txt");
        System.out.println(file.getName());
        MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("file", cbFile);
        httppost.setEntity(mpEntity);
        System.out.println("executing request " + httppost.getRequestLine());
        System.out.println("Now uploading your file into bayfiles.com");
        HttpResponse response = httpclient.execute(httppost);
        System.out.println("after exe");
        HttpEntity resEntity = response.getEntity();


        System.out.println(response.getStatusLine());
        if (resEntity != null) {
            uploadresponse = EntityUtils.toString(resEntity);
        }
//  
        System.out.println("Upload response : " + uploadresponse);
        downloadlink = parseResponse(uploadresponse, "\"downloadUrl\":\"", "\"");
        downloadlink = downloadlink.replaceAll("\\\\", "");
        deletelink = parseResponse(uploadresponse, "\"deleteUrl\":\"", "\"");
        deletelink = deletelink.replaceAll("\\\\", "");
        System.out.println("Download link : " + downloadlink);
        System.out.println("Delete link : " + deletelink);
    }

    public static void loginBayFiles() throws Exception {
        HttpParams params = new BasicHttpParams();
        params.setParameter(
                "http.useragent",
                "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6");
        DefaultHttpClient httpclient = new DefaultHttpClient(params);

        httpclient.getCredentialsProvider().setCredentials(
                new AuthScope(proxy_host, Integer.valueOf(proxy_port)),
                new UsernamePasswordCredentials("", ""));

        //    HttpHost targetHost = new HttpHost("www.verisign.com", 443, "https");
        HttpHost proxy = new HttpHost(proxy_port, Integer.valueOf(proxy_port));

        httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        System.out.println("Trying to log in to bayfiles.com");
        HttpPost httppost = new HttpPost("http://bayfiles.com/ajax_login");
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("action", "login"));
        formparams.add(new BasicNameValuePair("username", "myusername"));
        formparams.add(new BasicNameValuePair("password", "mypwd"));
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
        httppost.setEntity(entity);
        HttpResponse httpresponse = httpclient.execute(httppost);
        System.out.println("Getting cookies........");
        Iterator<Cookie> it = httpclient.getCookieStore().getCookies().iterator();
        Cookie escookie = null;
        while (it.hasNext()) {
            escookie = it.next();
            if (escookie.getName().equalsIgnoreCase("SESSID")) {
                sessioncookie = "SESSID=" + escookie.getValue();
                System.out.println(sessioncookie);
                login = true;
                System.out.println("BayFiles.com Login success :)");
            }
        }
        if (!login) {
            System.out.println("BayFiles.com Login failed :(");
        }
    }
}
  • 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-05T21:26:50+00:00Added an answer on June 5, 2026 at 9:26 pm

    I solve a similar problem using the default proxy selector:

    DefaultHttpClient httpclient = new DefaultHttpClient();
    
    ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner(
         httpclient.getConnectionManager().getSchemeRegistry(),
         ProxySelector.getDefault());
    
    httpclient.setRoutePlanner(routePlanner);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an upload script for students in my lab class to upload
Is there an easy/straightforward way to extend the file upload class to encrypt files
I'm working on an image gallery which allows the possibility to upload an image,
I am working on a Google Appengine Python project where users will upload a
I'm working with a solution provided by Cool Hand Luke UK which upload's a
I just uploaded working site files to a new server which I know is
I have a working s3 uploader in actionscript that uses the FileReference class so
I have a problem with dojox.form.Uploader. I want to use it to attach files
I am working on a Media up-loader which uploads images to Server. Before start
I'm working on a upload script and using move_uploaded_file() function. The problem is, that

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.