对于android–Uri.getQueryParameter()不使用“[”和“]”符号感兴趣的读者,本文将会是一篇不错的选择,并为您提供关于ACMESharp无效URI:URI方案无效、andro
对于android – Uri.getQueryParameter()不使用“[”和“]”符号感兴趣的读者,本文将会是一篇不错的选择,并为您提供关于ACMESharp 无效 URI:URI 方案无效、android – ImageView.setImageURI(Uri uri)是否可以使用远程文件?、android 关于 Uri.parse 和 uri.fromFile 的区别、Android:从内容 URI 获取文件 URI?的有用信息。
本文目录一览:- android – Uri.getQueryParameter()不使用“[”和“]”符号
- ACMESharp 无效 URI:URI 方案无效
- android – ImageView.setImageURI(Uri uri)是否可以使用远程文件?
- android 关于 Uri.parse 和 uri.fromFile 的区别
- Android:从内容 URI 获取文件 URI?
android – Uri.getQueryParameter()不使用“[”和“]”符号
uri.getQueryParameterNames()返回一个值为[“param1”,“param2 []”,“param3 [1]”]的数组,这是预期的.
但是当将这些值传递给getQueryParameter时,我得到:
uri.getQueryParameter(“param1”)==“1”
uri.getQueryParameter(“param2 []”)== null
uri.getQueryParameter(“param3 [1]”)== null
我试过没有括号部分传递参数的名称,它也不起作用.也调用getQueryParameters()不起作用.
谢谢你的帮助!
解决方法
如果向下滚动到规范中的第2.4.3节,您将找到以下内容:
Other characters are excluded because gateways and other transport
agents are kNown to sometimes modify such characters,or they are
used as delimiters.
unwise = "{" | "}" | "|" | "\" | "^" | "[" | "]" | "
“`Data corresponding to excluded characters must be escaped in order
to be properly represented within a URI.
从代码的角度来看,Uri有一个私有方法来确定是否允许一个字符 – 如果不允许,它将被编码.理论上,对于括号和其他特殊字符,这应该返回false.
/** * Returns true if the given character is allowed. * * @param c character to check * @param allow characters to allow * @return true if the character is allowed or false if it should be * encoded */ private static boolean isAllowed(char c,String allow) { return (c >= ''A'' && c <= ''Z'') || (c >= ''a'' && c <= ''z'') || (c >= ''0'' && c <= ''9'') || "_-!.~''()*".indexOf(c) != NOT_FOUND || (allow != null && allow.indexOf(c) != NOT_FOUND); }
话虽这么说,现在我们到了有趣的部分.看起来Uri.parse()相当’懒惰’,因为它实际上并不对你给它的uri进行编码.在您的场景中,您可能通过调用以下方式构建Uri:
Uri uri = Uri.parse("http://host/path?param1=1¶m2[]=2¶m3[1]=3");
然后,当您开始在生成的Uri上调用getQueryParameter()时,后台数据(String)是“未编码”,但是您提供给这些方法的参数名称会被编码.例如:
uri.getQueryParameter("param2[]")
实际上是:
uri.getQueryParameter("param2%5B%5D")
Uri中显然不存在具有键param2 []的查询参数.
解决方案是确保首先转义括号,或使用Uri.Builder.例如:
Uri uri = Uri.parse("http://host/path").buildUpon() .appendQueryParameter("param1","1") .appendQueryParameter("param2[]","2") .appendQueryParameter("param3[1]","3") .build();
这将导致以下基础uri:
http://host/path?param1=1¶m2%5B%5D=2¶m3%5B1%5D=3
然后你可以毫无问题地调用uri.getQueryParameter(“param3 [1]”):它将返回3.
编辑:我收回我所说的关于Uri.parse()懒惰的内容.它的目的是这样.正如Javadoc中明确提到的那样:
Creates a Uri which parses the given encoded URI string.
换句话说:您提供的用于解析的字符串应该已经正确编码.
ACMESharp 无效 URI:URI 方案无效
如何解决ACMESharp 无效 URI:URI 方案无效
我创建了一个脚本来自动为我的网站生成 Let''s Encrypt 证书的过程。 该脚本始终运行良好,但从昨天开始,当我尝试运行时,我收到以下问题:
New-AcmeRegistration -Contacts mailto:user@email.com -AcceptTos
错误:
System.UriFormatException: Invalid URI: The URI scheme is not valid.
at System.Uri.CreateThis(String uri,Boolean dontEscape,UriKind uriKind)
at AcmeSharp.AcmeClient.GetDirectory(Boolean saveRelative) in
C:\\projects\\acmesharp\\AcmeSharp\\AcmeSharp\\AcmeClient.cs:line 145
at AcmeSharp.POSH.NewRegistration.ProcessRecord() in
C:\\projects\\acmesharp\\AcmeSharp\\AcmeSharp.POSH\\NewRegistration.cs:line 63
at System.Management.Automation.CommandProcessor.ProcessRecord()
我安装了最新版本的 PowerShell 模块 (https://www.powershellgallery.com/packages/ACMESharp/0.9.1.326)。
有人遇到过类似的问题吗?
解决方法
由于 BaseUri: https://acme-v01.api.letsencrypt.org/directory 返回 JSON 错误而引发错误。 ACME 协议版本 1 已被弃用。您将需要使用使用 ACME 协议版本 2 的客户端。 考虑用 ACME-PS 替换 ACMESharp。
android – ImageView.setImageURI(Uri uri)是否可以使用远程文件?
解决方法
如果uri包含对本地文件的引用,则可以使用ImageView.setimageURI(Uri uri).例如:file:///sdcard/images/thumb.png
android 关于 Uri.parse 和 uri.fromFile 的区别
Uri.parse 需要有协议,如 file:// 等
比如下面 2 句话就是等价的
Uri.parse("file://" + new File(path).toString()) Uri.fromFile(new File(path))
Android:从内容 URI 获取文件 URI?
在我的应用程序中,用户将选择应用程序然后处理的音频文件。问题是,为了让应用程序执行我希望它对音频文件执行的操作,我需要 URI
为文件格式。当我使用Android的原生音乐播放器浏览app中的音频文件时,URI是一个内容URI,看起来是这样的:
content://media/external/audio/media/710
但是,使用流行的文件管理器应用程序 Astro,我得到以下信息:
file:///sdcard/media/audio/ringtones/GetupGetOut.mp3
后者对我来说更容易使用,但我当然希望应用程序具有用户选择的音频文件的功能,而不管他们使用什么程序来浏览他们的收藏。所以我的问题是,有没有办法将content://
样式
URI 转换为file://
URI?否则,您会建议我如何解决这个问题?这是调用选择器的代码,供参考:
Intent ringIntent = new Intent();ringIntent.setType("audio/mp3");ringIntent.setAction(Intent.ACTION_GET_CONTENT);ringIntent.addCategory(Intent.CATEGORY_OPENABLE);startActivityForResult(Intent.createChooser(ringIntent, "Select Ringtone"), SELECT_RINGTONE);
我对内容 URI 执行以下操作:
m_ringerPath = m_ringtoneUri.getPath();File file = new File(m_ringerPath);
然后用所述文件做一些 FileInputStream 的东西。
答案1
小编典典只需用于从 URIgetContentResolver().openInputStream(uri)
获取。InputStream
http://developer.android.com/reference/android/content/ContentResolver.html#openInputStream(android.net.Uri)
我们今天的关于android – Uri.getQueryParameter()不使用“[”和“]”符号的分享就到这里,谢谢您的阅读,如果想了解更多关于ACMESharp 无效 URI:URI 方案无效、android – ImageView.setImageURI(Uri uri)是否可以使用远程文件?、android 关于 Uri.parse 和 uri.fromFile 的区别、Android:从内容 URI 获取文件 URI?的相关信息,可以在本站进行搜索。
本文标签: