Tag: uri

如何获取URL的路径

有一个URL,如何检索其路径部分? http://www.costo.com/test1/test2 如何获得“test1 / test2”

使用URI类创建自定义URI方案

我需要为我的项目创建一个自定义URI方案。 即 urn:myprotocol:{p1}:{p2}:{p3}:{p4} – 不透明的表示 myprotocol://{p1}/{p2}/{p3}/{p4} – 分层表示。 如何将我的方案添加到Java URI类? 或者,我如何让Java URI理解我的方案,所以我可以在我的代码中使用它? 欢迎具体的例子。 谢谢。

转义并在url中

我使用的是jsps,在我的url中,我有一个变量的值,比如说“L&T”。 现在,当我尝试使用request.getParameter检索它的值时,我只得到“L”。 它将“&”识别为分隔符,因此不会将其视为整个字符串。 我该如何解决这个问题?

本地资源的URI

在Java中,我可以为位于硬盘驱动器本地的文件创建URI吗? 如果是这样,它应该如何构建?

如何将“jar:file”URI转换为Jar文件的路径?

我如何从jar:file:/C:/Program%20Files/test.jar!/foo/bar转到指向C:/Program Files/test.jar ?

当密码包含@时,“期望/遵循URI中的主机名”exception

我正在尝试将本地系统文件复制到服务器 package classes; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.util.Properties; import org.apache.commons.vfs.FileObject; import org.apache.commons.vfs.FileSystemOptions; import org.apache.commons.vfs.Selectors; import org.apache.commons.vfs.impl.StandardFileSystemManager; import org.apache.commons.vfs.provider.sftp.SftpFileSystemConfigBuilder; public class SendMyFiles { public static void main(String[] args) { SendMyFiles sendMyFiles = new SendMyFiles(); String fileToFTP = “zcol_30092013.xls”; sendMyFiles.startFTP(fileToFTP); } public boolean startFTP(String fileToFTP){ Properties prop = new Properties(); InputStream in = getClass().getResourceAsStream(“/config.properties”); […]

URI编码的URL将“%3D”更改为“%253D”

我在编写URI的URL时遇到问题: mUrl = “A string url that needs to be encoded for use in a new HttpGet()”; URL url = new URL(mUrl); URI uri = new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(), null); 这不符合我对以下URL的期望: 传入字符串: http://m.bloomingdales.com/img?url=http%3A%2F%2Fimages.bloomingdales.com%2Fis%2Fimage%2FBLM%2Fproducts%2F3%2Foptimized%2F1140443_fpx.tif%3Fwid%3D52%26qlt%3D90% 2C0%26layer%3Dcomp%26op_sharpen%3D0%26resMode%3Dsharp2%26op_usm%3D0.7%2C1.0%2C0.5%2C0%26fmt%3Djpeg&TTL = 30D 出来是: http://m.bloomingdales.com/img?url=http%253A%252F%252Fimages.bloomingdales.com%252Fis%252Fimage%252FBLM%252Fproducts%252F3%252Foptimized%252F1140443_fpx.tif%253Fwid%253D52%2526qlt%253D90% 252C0%2526layer%253Dcomp%2526op_sharpen%253D0%2526resMode%253Dsharp2%2526op_usm%253D0.7%252C1.0%252C0.5%252C0%2526fmt%253Djpeg&TTL = 30D 哪个坏了。 例如, %3D变成%253D它似乎对字符串中的%已经做了一些神秘的事情。 发生了什么事,我在这里做错了什么?

当相对URI包含空路径时,Java的URI.resolve是否与RFC 3986不兼容?

我相信Java的URI.resolve方法的定义和实现与RFC 3986第5.2.2节不兼容。 我知道Java API定义了该方法的工作方式,如果它现在被更改,它会破坏现有应用程序,但我的问题是: 任何人都可以确认我的理解这个方法与RFC 3986不兼容吗? 我正在使用这个问题中的示例: java.net.URI仅针对查询字符串进行解析 ,我将在此处复制: 我正在尝试使用JDK java.net.URI构建URI。 我想附加一个绝对URI对象,一个查询(在String中)。 例如: URI base = new URI(“http://example.com/something/more/long”); String queryString = “query=http://local:282/rand&action=aaaa”; URI query = new URI(null, null, null, queryString, null); URI result = base.resolve(query); 理论(或我认为)是决心应该回归: http://example.com/something/more/long?query=http://local:282/rand&action=aaaa 但我得到的是: http://example.com/something/more/?query=http://local:282/rand&action=aaaa 我对RFC 3986第5.2.2节的理解是,如果相对URI的路径为空,那么将使用基URI的整个路径: if (R.path == “”) then T.path = Base.path; if defined(R.query) then T.query = R.query; […]

无法使用java SoapMessage更改信封中的soap URI

我正在尝试创建一个从客户端发送的简单SOAP消息,但我(貌似)无法更改信封中“soap”命名空间的URI。 这就是soap标题应该是这样的: … 所以我有以下代码: final SOAPMessage sm = MessageFactory.newInstance().createMessage(); final SOAPPart sp = sm.getSOAPPart(); final SOAPEnvelope se = sp.getEnvelope(); final SOAPHeader sh = se.getHeader(); final SOAPBody sb = se.getBody(); se.removeNamespaceDeclaration(se.getPrefix()); se.addNamespaceDeclaration(“soap”, “http://www.w3.org/2001/12/soap-envelope”); se.setPrefix(“soap”); sb.setPrefix(“soap”); sh.setPrefix(“soap”); se.setEncodingStyle(“http://www.w3.org/2001/12/soap-encoding/”); 但是,当我在发送之前打印邮件时,以下是我的信封: 请注意“应该是”部分中的xmlns:soap的URI与实际的差异。 如果我将addNamespaceDeclaration调用的第一个参数更改为“ addNamespaceDeclaration ”而不是“soap”,这是我获得的以下信封: 我猜它可能与调用addNamespaceDeclaration而不是像changeNamespaceDeclaration这样的changeNamespaceDeclaration ,并且考虑到命名空间已经存在而忽略它,但我找不到changeNamespaceDeclaration东西(我已经尝试过setAttributeNS ) 。 编辑:我刚刚意识到setAttributeNS是愚蠢的,因为它改变了命名空间,而不是URI。 再次编辑:我有点困惑,因为我继续搜索,我有时会看到命名变成soap:”Namespace” ,所以在这个意义上我确实想要更改命名空间……但我认为命名空间是“肥皂“部分。 有任何澄清吗? 这是我的第一篇文章所以我道歉,如果我问的是已经解决过的东西,但我已经搜索过了,我发现的大部分内容与更改命名空间有关(比如SOAP-ENV,这是默认命名空间,而不是URI本身。 提前致谢。 -M

java.net.MalformedURLException:基于使用URLEncoder修改的字符串,URL上没有协议

所以我试图在URL中使用这个String: – http://site-test.collercapital.com/Meetings/IC/DownloadDocument?meetingId=c21c905c-8359-4bd6-b864-844709e05754&itemId=a4b724d1-282e-4b36-9d16-d619a807ba67&file=\\s604132shvw140\Test-Documents\c21c905c-8359-4bd6-b864-844709e05754_attachments\7e89c3cb-ce53-4a04-a9ee-1a584e157987\myDoc.pdf 在此代码中: – String fileToDownloadLocation = //The above string URL fileToDownload = new URL(fileToDownloadLocation); HttpGet httpget = new HttpGet(fileToDownload.toURI()); 但在这一点上我得到错误: – java.net.URISyntaxException: Illegal character in query at index 169:Blahblahblah 我通过一些谷歌搜索意识到这是由于URL中的字符(猜测&),所以我添加了一些代码,所以它现在看起来像这样: – String fileToDownloadLocation = //The above string fileToDownloadLocation = URLEncoder.encode(fileToDownloadLocation, “UTF-8”); URL fileToDownload = new URL(fileToDownloadLocation); HttpGet httpget = new HttpGet(fileToDownload.toURI()); 但是,当我尝试运行它时,当我尝试创建URL时出现错误,然后错误如下: – […]