Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting java exception: java.net.MalformedURLException: no protocol

Tags:

java

url

io

I am currently calling the following line of code:

java.net.URL connection_url = new java.net.URL("http://<ip address>:<port>/path");

and I get the exception above when it executes. Any ideas as to why this is happening?

like image 339
Craig H Avatar asked Sep 12 '08 20:09

Craig H


People also ask

How do I resolve Java net MalformedURLException?

Handling MalformedURLException The only Solution for this is to make sure that the url you have passed is legal, with a proper protocol. The best way to do it is validating the URL before you proceed with your program. For validation you can use regular expression or other libraries that provide url validators.

What is malformed URL exception?

Class MalformedURLExceptionThrown to indicate that a malformed URL has occurred. Either no legal protocol could be found in a specification string or the string could not be parsed.

What is a malformed URL?

This violation indicates that a request that was not created by a browser, and does not comply with HTTP standards, has been sent to the server. This may be the result of of an HTTP request being manually crafted or of a client tunneling other protocols over HTTP.


1 Answers

As a side note, you should be using URI because Java URL class is screwed up. (The equals method I believe)

like image 119
jjnguy Avatar answered Sep 20 '22 14:09

jjnguy