Tag: url

未知主机exception

try { { long startTime = System.currentTimeMillis(); String source=”s”; String source1=”s”; URL google = new URL(“http://google.com/”); HttpURLConnection yc =(HttpURLConnection)google.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { source=source.concat(inputLine); } in.close(); yc.disconnect(); } long endTime1 = System.currentTimeMillis(); System.out.println(“Total elapsed time in execution of method callMethod() is :”+ (endTime1-startTime)); } […]

Android:如何显示相同标记名称的所有XML值

我有ff。 来自URL的XML: Michael De Leon 5, Cat Street John Smith 6, Dog Street 我想显示两个PhonebookEntry值(名字,姓氏,地址)。 目前,我的代码仅显示John Smith的PhonebookEntry(最后一个条目)。 这是我的代码。 ParsingXML.java package com.example.parsingxml; import java.net.Proxy; import java.net.Socket; import java.net.SocketAddress; import java.net.URL; import java.net.URLConnection; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.InputSource; import org.xml.sax.XMLReader; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.TextView; public class ParsingXML extends Activity { /** Called when […]

如何将URL编码为“可浏览”?

我想知道是否有任何方法可以解析这样的URL: https://www.mysite.com/lot/of/unpleasant/folders/and/my/url with spaces &”others”.xls 成 https://www.mysite.com/lot/of/unpleasant/folders/and/my/url%20with%20spaces%20&%22others%22.xls 类似于Firefox在粘贴前URL时所做的URL重写,将其发送到服务器(除非您有这样的网站,否则无响应),然后从导航栏复制URL并将其粘贴到其他位置。 使用URLEncoder#encode给我这个(不需要的)输出: https%3A%2F%2Fwww.mysite.com%2Flot%2Fof%2Funpleasant%2Ffolders%2Fand%2Fmy%2Furl+with+spaces+%26%22others%22.xls 遗憾的是,我收到一个字符串,如问题的开头所示,所以使用URLEncoder#encode直接不起作用。 我天真地试过这个: String evilUrl = “https://www.mysite.com/lot/of/unpleasant/folders/and/my/url with spaces &\”others\”.xls”; URI uri = null; String[] urlParts = evilUrl.split(“://”); String scheme = urlParts[0]; urlParts = urlParts[1].split(“/”); String host = urlParts[0]; StringBuilder sb = new StringBuilder(‘/’); for (int i = 1; i < urlParts.length; i++) { sb.append('/'); sb.append(urlParts[i]); […]

Java中的URL连接(FTP) – 简单问题

我有一个简单的问题。 我正在尝试用Java将文件上传到我的ftp服务器。 我的计算机上有一个文件,我想制作该文件的副本并上传它。 我尝试手动将文件的每个字节写入输出流,但这对于复杂文件(如zip文件或pdf文件)不起作用。 File file = some file on my computer; String name = file.getName(); URL url = new URL(“ftp://user:password@domain.com/” + name +”;type=i”); URLConnection urlc = url.openConnection(); OutputStream os = urlc.getOutputStream(); //then what do I do? 只是为了踢,这是我试图做的: OutputStream os = urlc.getOutputStream(); BufferedReader br = new BufferedReader(new FileReader(file)); String line = br.readLine(); while(line != null […]

SpringBoot中的@PathVariable,带有URL中的斜杠

我必须在SpringBoot应用程序中使用@PathValiable从URL获取params。 这些参数常常有斜线 。 我无法控制用户在URL中输入的内容,因此我希望获得他输入的内容然后我可以处理它。 我已经在这里查看了材料和答案,我不认为对我来说好的解决方案是要求用户以某种方式编码输入参数。 SpringBoot代码很简单: @RequestMapping(“/modules/{moduleName}”) @ResponseBody public String moduleStrings (@PathVariable(“moduleName”) String moduleName) throws Exception { … } 所以URL例如如下: http://localhost:3000/modules/… 问题是param moduleName经常有斜杠。 例如, metadata-api\cb-metadata-services OR app-customization-service-impl\\modules\\expand-link-schemes\\common\\app-customization-service-api 因此用户可以定义输入: http://localhost:3000/modules/metadata-api\cb-metadata-services 这可以在/ modules /之后获取用户在URL中输入的所有内容吗? 如果有人告诉我处理此类问题的好方法是什么。

ImageIO.read()返回403错误

我有以下代码: public BufferedImage urlToImage(String imageUrl) throws MalformedURLException, IOException { URL url = new URL(imageUrl); BufferedImage image = ImageIO.read(url); return image; } 那应该是从给定的URL返回一个图像。 我测试了这两个随机选择的URL: http://sofzh.miximages.com/java/logo4w.png http://sofzh.miximages.com/java/osteoderms-storing-minerals-helped-huge-dinosaurs-survive_3011.jpg 第一个工作正常,但第二个给出403错误: Caused by: java.io.IOException: Server returned HTTP response code: 403 for URL: http://sofzh.miximages.com/java/osteoderms-storing-minerals-helped-huge-dinosaurs-survive_3011.jpg at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1436) at java.net.URL.openStream(URL.java:1010) at javax.imageio.ImageIO.read(ImageIO.java:1367) 可能是错误的原因是什么? 谢谢。

如何确定给定的URL链接是video还是图像?

我正在尝试获取用户输入的给定URL,并确定该URL是指向图像还是video。 用例示例: 当用户粘贴YouTubevideo的url时,在保存页面时会自动显示嵌入的YouTube播放器。 当用户在Flickr中发布图片的URL时,在保存时,该页面将自动显示较小版本的Flickr图像。

将URL解析为组件

我想在Java中使用斜杠(例如server/books/thrillers/johngrisham/thefirm )解析描述性样式的URL。 我的总体想法是处理我收到的数据,以便在数据库中进行查找(因此使用URL作为搜索条件),然后返回包含数据的HTML页面。 我该怎么做呢?

如何获取URL的路径

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

获取程序正在运行的.jar文件的URL

给定使用maven编译的hello.jar,我想访问位于folder / file.file下的资源。 但是我不知道如何获取我所在的当前JAR的URL file://./folder/file.file 工作正常,或, jar:file://./!hello.jar/folder/file.file 或者有更简单的方法吗? (抱歉这个愚蠢的问题,我是maven的新手。)