Some robustness fix
This commit is contained in:
parent
5fd11daf15
commit
186714d0b2
1 changed files with 12 additions and 1 deletions
|
|
@ -32,6 +32,7 @@ import javax.net.ssl.SSLSocketFactory;
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
@ -90,6 +91,14 @@ public class HttpClient implements AutoCloseable {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setURL(String url) {
|
||||||
|
try {
|
||||||
|
setURL(new HttpURL(url));
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
throw new IllegalArgumentException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setURL(URL url) {
|
public void setURL(URL url) {
|
||||||
setURL(new HttpURL(url));
|
setURL(new HttpURL(url));
|
||||||
}
|
}
|
||||||
|
|
@ -140,7 +149,9 @@ public class HttpClient implements AutoCloseable {
|
||||||
*/
|
*/
|
||||||
public HttpHeader send() throws IOException {
|
public HttpHeader send() throws IOException {
|
||||||
int port = 80;
|
int port = 80;
|
||||||
if (url.getPort() > 0)
|
if (url == null)
|
||||||
|
throw new IllegalArgumentException("No URL defined for request.");
|
||||||
|
else if (url.getPort() > 0)
|
||||||
port = url.getPort();
|
port = url.getPort();
|
||||||
else if ("https".equals(url.getProtocol()))
|
else if ("https".equals(url.getProtocol()))
|
||||||
port = 443;
|
port = 443;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue