English 中文(简体)
无法在代理服务器背后从互联网下载文件
原标题:Unable to download file from internet behind a proxy

我的应用程序在互联网上下载一个文件, 从给定链接下载。 我使用我的研究所的互联网连接, 使用代理设置 。

要让我的应用程序能够从互联网下载文件, 我需要打开我的互联网浏览器, 为连接提供用户名和密码, 并保持浏览器运行, 只有这样, 我的应用程序才能下载完整文件, 如果我不做这些事情, 我的应用程序正常运行, 在想要的地方创建一个文件, 但显示的文件大小为零, 而这很可能是因为它无法直接连接到互联网 。

若无法使用用户名和密码, 如何能让我的应用程序显示一个对话,

谢谢:-)

最佳回答

当您创建连接对象以进行文件传输时, 您必须指定您正在使用代理服务器所期待的任何形式的认证证书。 我不知道您在爪哇为Android做什么, 但是在. NET I 做这个:

  LogHandler.Log(LogHandler.LogType.Debug, "Configure proxy credentials");

  // Proxy address and port
  ec2Config.ProxyHost = ConfigurationManager.AppSettings["LocalProxyHost"];
  ec2Config.ProxyPort = Convert.ToInt32(ConfigurationManager.AppSettings["LocalProxyPort"]);

  // Create a dummy webrequest so we can set proxy credentials (to stop the proxy spitting 407s at us)
  HttpWebRequest dummyRequest = (HttpWebRequest)WebRequest.Create(ec2Config.ServiceURL);
  dummyRequest.Proxy.Credentials = CredentialCache.DefaultCredentials;

  #pragma warning disable 168
  HttpWebResponse myHttpWebResponse = (HttpWebResponse)dummyRequest.GetResponse();
  #pragma warning restore 168
问题回答

我开发了这个逻辑, 需要很多工作, 但有助于我发现是否有其它问题, 比如代理问题或其他问题, 因为正常的互联网连通经理无法检测是否需要认证。

 final ConnectivityManager conMgr =  (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
  final NetworkInfo activeNetwork = conMgr.getActiveNetworkInfo();

            if (activeNetwork != null && activeNetwork.getState() == NetworkInfo.State.CONNECTED) {

                            //Do what ever you wish to do

                            } else {
                                  // Display message internet connection not available
                                  }

上述代码提供了互联网连接是否可用的信息,但是它会显示互联网连接是否需要认证,因此在检查上述条件后,我试图访问链接下载,然后使用这一逻辑。

我使用的逻辑在这个堆积流查询(......希望这些信息帮助有需要的人。





相关问题
How to upload and download file from a server using C#

I am developing a webpage in that the user can download their Resume for Edit. So I have a link to download the article. I use the following code for download. DataTable dt = user.getUserDetails(2); ...

Detecting PDF Download

I have recently added functionality for generating pdf reports to a web application. However the reports can be quite large and take some time to show the pdf download dialog. I want to show a spinner ...

Writing file to users giving sporadic error in IE

I have a very interesting issue with only specific IE implementations. I have an ASPX page that is used to write files down to the user, as part of the process the page uses the following code to ...

PHP - List of Excel files to download from Intranet Site?

I have a intranet site running PHP 5 that needs to list a folder containing only Excel files. Ideally the user needs to be able to input some search criteria (ie date) and the files would be filtered ...

Determine total size of SVN directory/trunk

Is there a way to count/calculate the total size of a svn directory if you were to checkout a revision? I have limited internet downloads so I need to know how big something is before I go and ...

Scala and html: download an image (*.jpg, etc) to Hard drive

I ve got a Scala program that downloads and parses html. I got the links to the image files form the html, Now I need to transfer those images to my hard drive. I m wondering what the best Scala ...

Downloading file with wxHTTP?

Im really stumped. Im using the wxHTTP class in wxWidgets to try and download two files. The first request succeeds but the second one fails when wxHTTP->GetInputStream is called. Between downloads, ...

热门标签