标签: webclient-download

我如何使用DownloadListener?

我正在创建一个应用程序,允许大学生从应用程序而不是浏览器下载他们的学习材料.主页有很多主题名称.每个主题名称都会导致新的网页.所以,我用过WebViewClient.但是,在最后一页,当我点击*.ppt或*.pdf文件时,它会打开垃圾.

我希望在应用程序中下载这些文件.

我该如何实施 DownloadListener

package jiit.app;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class sm extends Activity
{  
    WebView browser;

    protected void onCreate(Bundle anyvar) 
    {
        super.onCreate(anyvar);
        setContentView(R.layout.sm);
        browser=(WebView)findViewById(R.id.webkit);
        WebSettings webSettings = browser.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setBuiltInZoomControls(true);
        browser.getSettings().setDefaultZoom(WebSettings.ZoomDensity.CLOSE);
        browser.setWebViewClient(new WebViewClient());
        {
            browser.loadUrl("http://www.sm.ividhya.com/j128/");
        }  
    }
}
Run Code Online (Sandbox Code Playgroud)

android webviewclient webclient-download

5
推荐指数
1
解决办法
2万
查看次数

在Windows Phone 8中以编程方式下载媒体文件

我们的应用程序是基于视频/音频的应用程序,我们已经在Windows Azure上传了所有媒体.

但是,需要方便用户按需下载音频/视频文件,以便他们可以在本地播放.

所以我需要以编程方式下载音频/视频文件并将其保存在IsolatedStorage中.

我们为每个音频/视频提供Windows Azure媒体文件访问URL.但我陷入下载媒体文件的第一步.

我用Google搜索并看到了这篇文章,但对于WebClient,我没有可以使用的函数DownloadFileAsync.

但是我尝试了其他函数DownloadStringAsyn,并且下载媒体文件是字符串格式但不知道如何将其转换为音频(wma)/视频(mp4)格式.请建议我,我该怎么办?还有其他方式下载媒体文件吗?

这是我使用的示例代码

private void ApplicationBarMenuItem_Click_1(object sender, EventArgs e)
    {
        WebClient mediaWC = new WebClient();
        mediaWC.DownloadProgressChanged += new DownloadProgressChangedEventHandler(mediaWC_DownloadProgressChanged);
        mediaWC.DownloadStringAsync(new Uri(link));            
        mediaWC.DownloadStringCompleted += new DownloadStringCompletedEventHandler(mediaWC_DownloadCompleted);           

    }

    private void mediaWC_DownloadCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        if (e.Cancelled)
            MessageBox.Show("Downloading is cancelled");
        else
        {
            MessageBox.Show("Downloaded");
        }
    }   

    private void mediaWC_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
    {
        statusbar.Text = status= e.ProgressPercentage.ToString();
    }
Run Code Online (Sandbox Code Playgroud)

audio video webclient-download windows-phone-8

5
推荐指数
1
解决办法
1508
查看次数

使用c#使下载可恢复

我正在使用此方法(WebClientClass)从Internet下载文件:

private Task DownloadUpdate(string url, string fileName)
{
       var wc = new WebClient();
       return wc.DownloadFileTaskAsync(new Uri(url), @"c:\download" + fileName);
}
Run Code Online (Sandbox Code Playgroud)

如何使用上述代码使下载恢复

c# asynchronous webclient-download

5
推荐指数
1
解决办法
4664
查看次数

WebClient DownloadFile-访问被拒绝或找不到路径的一部分

我试图设置一个按钮,以便用户可以下载保存在服务器上的文件。

protected void btnDownloadHtmlFile_Click(object sender, EventArgs e)
{
    string path = @"D:\web\mytestwebsite.com\www\temp\test.html";
    if (!File.Exists(path))
    {
        File.Create(path);
    }

    TextWriter tw = new StreamWriter(path);
    tw.WriteLine("<head></head><body>test</body>");
    tw.Close();

    WebClient webclient = new WebClient();
    webclient.DownloadFile(@"D:\web\mytestwebsite.com\www\temp\test.html", @"C:\web\test.html");
}
Run Code Online (Sandbox Code Playgroud)

Could not find a part of the path 'C:\web\test.html'. 如果我更改为相同结果

 webclient.DownloadFile(new Uri("http://mytestwebsite.com/temp/test.html"), @"C:\web\test.html");
Run Code Online (Sandbox Code Playgroud)

如果我换了

webclient.DownloadFile(@"D:\web\mytestwebsite.com\www\temp\test.html", "test.html");
Run Code Online (Sandbox Code Playgroud)

要么

webclient.DownloadFile(new Uri("http://mytestwebsite.com/temp/test.html"), "test.html");
Run Code Online (Sandbox Code Playgroud)

我获得对路径'C:\ Windows \ SysWOW64 \ inetsrv \ test.html'的访问被拒绝。

最后,我进入文件夹C:\ Windows \ SysWOW64 \ inetsrv,授予NETWORK SERVICE权限,但是它说访问被拒绝。我在服务器上以管理员身份登录。

我读了一些关于此的文章,但似乎没有任何作用,或者我错过了一些东西。

什么是使用WebcClient.DownloadFile的正确方法?

c# asp.net webclient-download

5
推荐指数
1
解决办法
1万
查看次数

Excel 文件通过 web api 下载。变得腐败

我正在尝试通过 Web API(使用实体框架)下载 excel 文件。下载正在运行,但我在尝试打开文件时收到一些关于文件损坏的错误对话框。

Web API 代码如下:

  public HttpResponseMessage GetValue(int ID, string name)
    {

    MemoryStream stream;
    try {
        using (DataContext db = new DataContext()) {
            dynamic fileObj = (from c in db.FileList c.ID == IDc).ToList();
            stream = new MemoryStream(fileObj(0).File);
            HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
            result.Content = new StreamContent(stream);
            result.Content.Headers.ContentType = new MediaTypeHeaderValue(fileObj(0).FileContentType);
            result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = name };
            return result;
        }
    } catch (Exception ex) {
        return Request.CreateResponse(HttpStatusCode.InternalServerError);
    }
}
Run Code Online (Sandbox Code Playgroud)

它打开带有两个错误对话框和以下消息的文件。

Excel 完成了文件级验证和修复。此工作簿的某些部分可能已被修复或丢弃

在此处输入图片说明

在此处输入图片说明

excel entity-framework webclient-download asp.net-web-api

5
推荐指数
1
解决办法
1698
查看次数

在Windows命令提示符/ PowerShell中下载大文件

我现在有点没钱了...

尝试1

在Powershell中使用iwr。它可以工作,显示进度,但速度慢10倍,直到文件在内存中才刷新:(。

 powershell -command "& { iwr https://github.com/mitchellspryn/AirsimHighPolySuv/releases/download/V1.0.0/SUV.zip -OutFile SUV.zip }"
Run Code Online (Sandbox Code Playgroud)

尝试2

在Powershell中使用.Net webclient。它有效,但是没有任何进展,您无法通过Ctrl + C :(。终止。

powershell -command "& { (New-Object System.Net.WebClient).DownloadFile('https://github.com/mitchellspryn/AirsimHighPolySuv/releases/download/V1.0.0/SUV.zip', 'SUV.zip') }"
Run Code Online (Sandbox Code Playgroud)

尝试3

在Powershell中使用BITS传输。它可以工作,显示进度并且几乎完美……直到您发现它神秘地在GitHub上不起作用(错误禁止403)!

powershell -command "& { Start-BitsTransfer -Source https://github.com/mitchellspryn/AirsimHighPolySuv/releases/download/V1.0.0/SUV.zip -Destination SUV.zip }"
Run Code Online (Sandbox Code Playgroud)

powershell command-line webclient-download microsoft-bits

5
推荐指数
2
解决办法
2220
查看次数

Android WebView 无法在 UIDAI/Aadhaar 网站上的 DownloadStart 上下载文件

我正在使用 Webview 从 UIDAI 网站在我的应用程序中下载 .zip 文件。但是,当 DownloadListener 被调用时,它会返回正确的数据,但会在该 .zip 文件中下载该 HTML 网页,而不是下载实际文件。而当我尝试通过 chrome 下载相同的 zip 时。它正在下载正确的 zip 文件。请帮我解决这个问题。为什么在这个特定网站 ( https://resident.uidai.gov.in/offline-kyc) 的webview 中会发生这种情况,而使用相同的下载侦听器我可以在其他网站上下载文件?

我的代码:

public class wvDownloadFile extends AppCompatActivity {

private static final int MY_PERMISSION_REQUEST_CODE = 123;
String QT_TAG = "download test";

String fileName = "test";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    WebView wv = findViewById(R.id.web_view);

    checkPermission();
    String url = "https://resident.uidai.gov.in/offline-kyc";
    wv.loadUrl(url);
    wv.getSettings().setJavaScriptEnabled(true);
    wv.getSettings().setSupportMultipleWindows(true);
    wv.getSettings().setAllowContentAccess(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        wv.getSettings().setAllowUniversalAccessFromFileURLs(true);
    }

    wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    wv.getSettings().setBuiltInZoomControls(false);
    wv.getSettings().setJavaScriptEnabled(true);
    wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    wv.getSettings().setAllowFileAccess(true); …
Run Code Online (Sandbox Code Playgroud)

android download-manager webview webclient-download

5
推荐指数
1
解决办法
368
查看次数

远程服务器(403)使用WebClient时出现禁止错误

我正在尝试使用查询某些URL WebClient.

我有一个集合,我循环来获取QueryString值,并构建最终的URL,然后将其传递给客户端.

它第一次执行得很好,我得到了适当的响应,然而,当它第二次进入循环时,我得到错误:

System.Net.WebException - >远程服务器返回错误:(403)Forbidden.

如果我第一次得到回复.然后我也应该得到其余的收藏品.

有什么线索的原因?我可能会缺少什么?

以下是我正在使用的代码段.

 using(System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\sample.text")) {
    foreach(var f in fileCollections) {
        strFinalURL = string.Empty;

        strFinalURL = "someURL" + f; // f can be considered as querystring param value

        try {
            using(var client = new WebClient()) {

                test = client.DownloadString(strFinalURL);
                if (!test.Contains("somecondition")) {
                    file.WriteLine("");
                }
            }
        } catch (System.Exception ex) {
            Console.WriteLine(ex.Message);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# webclient webclient-download

4
推荐指数
1
解决办法
1万
查看次数

如何使用 C# 从 URL 下载 ZIP 文件?

我想从某个网址下载 ZIP 文件。当我打开浏览器并写入URL时,浏览器直接开始下载ZIP文件。但是,我想要的是使用 C# 代码自动执行此操作。

我尝试了以下代码:

private void btnDownload_Click(object sender, EventArgs e) {
  WebClient webClient = new WebClient();
  webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed); 
  webClient.DownloadFileAsync(new Uri("http://---/file.zip"), @"c:\file.zip");
}     

private void Completed(object sender, AsyncCompletedEventArgs e) {
  MessageBox.Show("Download completed!");
}
Run Code Online (Sandbox Code Playgroud)

似乎下载正在运行,但是当我检查下载的文件时,我发现它为0 KB。

知道发生了什么吗?

c# url webclient webclient-download

4
推荐指数
1
解决办法
2万
查看次数

在 C# 中从 github 下载 zipball

需要从 C# 中的给定链接下载一个 zipball

是的!我搜索了网络和 stackoverflow 并试图完成这个看似不可能的任务几个小时......

具有讽刺意味的是,在 Curl 中,它是单行的,就像魅力一样。

curl -L https://api.github.com/repos/username/reponame/zipball > repo.zip
Run Code Online (Sandbox Code Playgroud)

我想在 C# 中做同样的事情 curl 在上面做...

尝试WebClient.DownloadFile() 给予

禁止 (403)

也尝试了异步方法

0 再见文件(无错误/异常)

尝试 HttpClient Datadownload 和 File stream writer,给出与上述相同的错误。根本没有调用像 streamwirter 这样的接缝,所以它无法访问服务器,这是我问题的主要部分

我安装了 Octokit.NET 但它缺少文档所以我什至不确定从哪里开始这样做(可能是 WebClient 版本,但我确实在 .NET 库中尝试过)

找到了这个答案,但并没有真正理解它(无法在 Octokit.net 中将存储库内容作为 .zip 文件(zipball)获取

甚至试图在 C# 中运行 .sh 脚本,但它给了我一个例外,它不能在这个操作系统上运行这种 shell

c# github-api webclient-download

3
推荐指数
1
解决办法
2469
查看次数