我url来自用户,我必须回复提取的HTML.
如何检查URL是否格式错误?
例如 :
url='google' // Malformed
url='google.com' // Malformed
url='http://google.com' // Valid
url='http://google' // Malformed
Run Code Online (Sandbox Code Playgroud)
我们怎样才能做到这一点?
所以我试图在URL中使用这个字符串: -
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
Run Code Online (Sandbox Code Playgroud)
在这段代码中: -
String fileToDownloadLocation = //The above string
URL fileToDownload = new URL(fileToDownloadLocation);
HttpGet httpget = new HttpGet(fileToDownload.toURI());
Run Code Online (Sandbox Code Playgroud)
但在这一点上我得到错误: -
java.net.URISyntaxException: Illegal character in query at index 169:Blahblahblah
Run Code Online (Sandbox Code Playgroud)
我通过一些谷歌搜索意识到这是由于URL中的字符(猜测&),所以我在一些代码中添加,所以它现在看起来像这样: -
String fileToDownloadLocation = //The above string
fileToDownloadLocation = URLEncoder.encode(fileToDownloadLocation, "UTF-8");
URL fileToDownload = new URL(fileToDownloadLocation);
HttpGet httpget = new HttpGet(fileToDownload.toURI());
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试运行它时,当我尝试创建URL时出现错误,然后错误如下: -
java.net.MalformedURLException: no protocol: http%3A%2F%2Fsite-test.collercapital.com%2FMeetings%2FIC%2FDownloadDocument%3FmeetingId%3Dc21c905c-8359-4bd6-b864-844709e05754%26itemId%3Da4b724d1-282e-4b36-9d16-d619a807ba67%26file%3D%5C%5Cs604132shvw140%5CTest-Documents%5Cc21c905c-8359-4bd6-b864-844709e05754_attachments%5C7e89c3cb-ce53-4a04-a9ee-1a584e157987%myDoc.pdf
Run Code Online (Sandbox Code Playgroud)
在我创建了URL之后看起来我不能进行编码,否则它会替换斜杠和不应该的东西,但是我看不出如何用字符串创建URL然后将其格式化它适合使用.我对这一切并不是特别熟悉,并希望有人能够指出我错过了将字符串A放入适当格式化的URL然后使用正确的字符替换?
任何建议都非常感谢!
URL u =新URL("telnet://route-server.exodus.net");
这条线正在产生:
java.net.MalformedURLException:未知协议:telnet
我遇到与以"news://"开头的其他网址类似的问题
这些是从ODP中提取的URL,所以我不明白为什么会出现这样的例外情况.
我正在尝试在我正在构建的Android应用程序中发出一个http POST请求,但无论我使用什么URL请求,Eclipse都会引发格式错误的URL异常.我已经尝试了一个Android教程中的一行代码:
URL url = new URL("https://wikipedia.org");
Run Code Online (Sandbox Code Playgroud)
甚至那会触发错误.是否有理由为我尝试创建的任何URL不断引发此错误?
我们在我们的应用程序中使用tomcat 7.0.27.我们在tomcat启动时设置jmx属性.
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port = 8666 -Dcom.sun.management.jmxremote.ssl = false -Dcom.sun.management.jmxremote.authenticate = false
如果运行此tomcat的centOS服务器主机名设置为所有数值,如005056940096,则tomcat无法启动.它给出了以下例外.
错误:代理抛出异常:java.net.MalformedURLException:本地主机名未知:java.net.UnknownHostException:005056940096:005056940096服务器正在centOS6上运行.如果hostname设置为非数字值,则它可以正常工作.
我尝试在/ etc/hosts和/ etc/sysconfig/network中设置主机名,但它仍然无效.我也尝试将下面的属性设置为服务器IP地址,但它仍然无法正常工作.-Djava.rmi.server.hostname = $ {} IP
如果您遇到任何此类问题,请告诉我.谢谢.
我有一个属性文件,其中包含一个属性,指定包含温度数据集的NOAA网站的URL.该属性包含一个[DATE_REPLACE]令牌,因为当NOAA生成新预测时,URL会每天更改.
在我的属性文件中,我指定:
WEATHER_DATA_URL="http://weather.noaa.gov/pub/SL.us008001/DF.anf/DC.mos/DS.mex/RD.[DATE_REPLACE]/cy.00.txt"
Run Code Online (Sandbox Code Playgroud)
我已经声明了一个带有PropertyHelper类(java.util.Properties的包装器)的方法,使用WEATHER_DATA_URL名称" yyyyMMdd "作为日期格式生成当天的URL字符串,即今天的日期.
public String getPropertyWithDateReplaceToken(String name, String dateFormat, Date dateToFormat)
{
String value = this.properties.getProperty(name);
if (StringHelper.isNullOrWhitespace(value) || !value.contains("[DATE_REPLACE]"))
{
throw new UnsupportedOperationException("The property value should specify the [DATE_REPLACE] token");
}
StringBuilder sb = new StringBuilder(value);
int index = sb.indexOf("[DATE_REPLACE]");
while (index != -1)
{
String replacement = StringHelper.getTodayAsDateString(dateFormat, dateToFormat);
sb.replace(index, index + "[DATE_REPLACE]".length(), replacement);
index += replacement.length();
index = sb.indexOf(value, index);
}
return sb.toString();
}
Run Code Online (Sandbox Code Playgroud)
然后,我使用以下方法调用另一个帮助器类来从网页中读取文本:
public static List<String> readLinesFromWebPage(String urlText) …Run Code Online (Sandbox Code Playgroud) 操作系统:Windows 7 32位JDK:jdk1.7.0_25
我有Studio.jnlp文件.我试图通过双击打开它.但我发现错误如下:
"MalformedURLException:unknown protocol:socket"详细信息:java.net.MalformedURLException:未知协议:socket


我是扩展开发的新手,
我尝试使用权限 url,因为
"<all_urls>
"*"
"http://*/*", "https://*/*"
没有任何模式有效
完整清单:
{
"name": "Info",
"description": "BS System Info",
"version": "1.0",
"manifest_version": 3,
"background": {
"service_worker": "background.js"
},
"content_scripts": [{
"js": ["script.js"],
"matches": ["http://*/*","https://*/*","<all_urls>"],
"css" : []
}],
"permissions": [
"storage",
"activeTab",
"system.cpu",
"system.memory",
"system.storage",
"system.display",
"tabs",
"scripting",
"http://*/*", "https://*/*", "chrome-devtools://*/*"
],
"action": {
"default_popup": "index.html",
"default_icon": {
"16": "/images/icon_16.png",
"32": "/images/icon_32.png",
"48": "/images/icon_48.png",
"128":"/images/icon_128.png"
}
}
}
Run Code Online (Sandbox Code Playgroud) 我收到此错误:
java.net.MalformedURLException: Protocol not found[java.lang.StringBuilder]
Run Code Online (Sandbox Code Playgroud)
执行以下行时:
url = new URL(urlString.toString());
Run Code Online (Sandbox Code Playgroud)
urlString存储以下值:
http://maps.google.com/maps?f=d&hl=en&saddr=25.04202,121.534761&daddr=25.05202,121.554761&ie=UTF8&0&om=0&output=kml
Run Code Online (Sandbox Code Playgroud)
是什么导致这种例外?
我正在使用 JAXB 来解组 XML 文档。解析 XML 时,它会抛出用 XMLStreamException 包装的 MalformedURLException。我的理解是,在创建 XMLStreamReader 对象本身时,它会抛出异常。请问有什么建议吗?
我正在使用的代码片段:
XMLInputFactory xif = XMLInputFactory.newFactory();
XMLResolver resolver = new XMLResolver(); //to capture systemID, base URI etc.
xif.setXMLResolver(resolver);
//Throws MalformedURLException while processing the below line
XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(fileToProcess));
JAXBContext jaxbContext = JAXBContext.newInstance(MyPackage.MyClassName.class);
Run Code Online (Sandbox Code Playgroud)
这是异常跟踪:
class javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException: java.net.MalformedURLException: no protocol: [XML_FILEPATH/XML_FILE_NAME]
Run Code Online (Sandbox Code Playgroud)
fileToProcess是包含绝对路径的字符串,例如 /home/project/input/myproject.xml
运行时 JDK 是 1.7。我缺少任何签名/协议吗?
谢谢,巴斯卡
我试图从我的Android应用程序中加载图像(http://www.elifeshopping.com/images/stories/virtuemart/product/thumbnail(2).jpg)BitmapFactory,代码如下:
try {
// ImageView i = (ImageView)findViewById(R.id.image);
bitmap = BitmapFactory.decodeStream((InputStream) new URL(url)
.getContent());
i.setImageBitmap(bitmap);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
我明白了
05-03 15:57:13.156: W/System.err(1086): java.net.MalformedURLException: Protocol not found: 9
05-03 15:57:13.167: W/System.err(1086): at java.net.URL.<init>(URL.java:273)
05-03 15:57:13.167: W/System.err(1086):
at java.net.URL.<init>(URL.java:157).
Run Code Online (Sandbox Code Playgroud)
请告诉我我做错了什么.
在 android 中使用 Android-Volley 时出现以下错误。同样的问题在这里也仍未解决......
\n\n08-27 14:46:18.779 26990-26990/com.rev.volleydemo D/VOLLEY\xef\xb9\x95 http://api.androidhive.info/volley/person_object.json\n08-27 14:46:18.879 26990-27004/com.rev.volleydemo E/Volley\xef\xb9\x95 [619] NetworkDispatcher.run: Unhandled exception java.lang.RuntimeException: Bad URL null\n java.lang.RuntimeException: Bad URL null\n at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:151)\n at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:114)\n Caused by: java.net.MalformedURLException\n at java.net.URL.<init>(URL.java:154)\n at java.net.URL.<init>(URL.java:127)\n at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:102)\n at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:97)\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:114)\nRun Code Online (Sandbox Code Playgroud)\n\npublic class AppController extends Application {\n\n public static final String TAG = AppController.class\n .getSimpleName();\n\n private RequestQueue mRequestQueue;\n private ImageLoader mImageLoader;\n\n private static AppController mInstance;\n\n @Override\n public void onCreate() {\n super.onCreate();\n mInstance = this;\n }\n\n …Run Code Online (Sandbox Code Playgroud)