android打开文件管理获取文件名,使用Android中的DownloadManager从标头中获取文件名...

如果有人想要执行HEAD请求来获取文件名:

class GetFileName extends AsyncTask

{

protected String doInBackground(String... urls)

{

URL url;

String filename = null;

try {

url = new URL(urls[0]);

String cookie = CookieManager.getInstance().getCookie(urls[0]);

HttpURLConnection con = (HttpURLConnection) url.openConnection();

con.setRequestProperty("Cookie", cookie);

con.setRequestMethod("HEAD");

con.setInstanceFollowRedirects(false);

con.connect();

String content = con.getHeaderField("Content-Disposition");

String contentSplit[] = content.split("filename=");

filename = contentSplit[1].replace("filename=", "").replace("\"", "").trim();

} catch (MalformedURLException e1) {

e1.printStackTrace();

} catch (IOException e) {

}

return filename;

}

@Override

protected void onPreExecute() {

super.onPreExecute();

}

@Override

protected void onPostExecute(String result) {

}

}

在Unity使用WebViewPrefab的LoadUrl方法打开带自定义标头的网页,您可以按照以下步骤进行操作: 1. 首先,确保您已经正确地将WebViewPrefab添加到场景,并将其设置为可见。 2. 获取WebViewPrefab组件的引用,您可以通过以下方式之一获取: - 在代码声明一个公共变量,并在Unity编辑器将WebViewPrefab拖放到该变量上。 - 通过代码获取GameObject并使用GetComponent方法获取WebViewPrefab组件。 3. 创建一个Dictionary<string, string>类型的变量,用于存储自定义标头。这个字典将存储每个标头的键值对。 4. 在字典添加您要发送的自定义标头。例如,如果您要添加一个名为"Authorization"的标头,值为"Bearer token",可以使用以下代码: ```csharp Dictionary<string, string> headers = new Dictionary<string, string>(); headers.Add("Authorization", "Bearer token"); ``` 5. 使用LoadUrl方法加载网页并传递自定义标头字典作为参数。例如,如果要加载一个URL为"https://example.com"的网页,您可以使用以下代码: ```csharp webViewPrefab.WebView.LoadUrl("https://example.com", headers); ``` 6. 确保在加载网页之前WebViewPrefab已经完成初始化,并且在调用LoadUrl之前WebViewPrefab已经准备就绪。 通过以上步骤,您可以在Unity使用WebViewPrefab的LoadUrl方法打开带有自定义标头的网页。请注意,具体的实现可能会根据您使用的WebView插件或库以及其提供的API有所不同,所以请参考相关文档和示例代码以获取更准确的操作指导。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值