java - org.apache.http.ProtocolException: Target host is not specified -
I have written a simple httprequest / response code and I am getting this error below: I used to type in my classpath httpclient, httpcore, common -Codecs and general logging. I am very new to Java and I do not know what's going on here. Please help me.
code:
import org.apache.http.client.HttpClient; Import org.apache.http.client.methods.HttpGet; Import org.apache.http.HttpResponse; Import org.apache.http.impl.client.HttpClientBuilder; Import org.apache.http.Header; Import org.apache.http.HttpHeaders; Public class UnshorteningUrl {public static zero main (string [] args throws exception {HttpGet request = zero; HTTP Client Client = HTTP ClientBuilder.credit (). Build (); Try {Request = New HTTP Gate ("trib.me/1lBFzSi"); HttpResponse httpResponse = client.execute (request); Header [] header = httpResponse.getHeaders (HttpHeaders.LOCATION); // Preconditions.checkState (headers.length == 1); String new url = header [0] .getValue (); System.out.println ("new url" + new URL); } Hold (illegal illegal exception e) {// TODO: finally disposed exception} {if (request! = Null) {request.releaseConnection (); }}}}
Error:
Exception in formula "main" org.apache.http.impl on org.apache.http.client.ClientProtocolException .client.InternalHttpClient.doExecute (InternalHttpClient.java:186) org.apache.http.impl.client.CloseableHttpClient.execute (CloseableHttpClient.java:82) on org.apache.http.impl.client.CloseableHttpClient.execute (CloseableHttpClient Java: org.apache.http.ProtocolException: 106) target due on org.apache.http.impl.client.CloseableHttpClient.execute (CloseableHttpClient.java:57) UnshorteningUrl.main (UnshorteningUrl.java:26) host org on org.apache.http.impl.client.InternalHttpClient.determineRoute (InternalHttpClient.java:124) on .apache is not specified in org.apache.http.impl.conn.DefaultRoutePlanner.determineRoute (DefaultRoutePlanner.java:69). http.impl.client.InternalHttpClient.doExecute (InternalHttpClient.java:183) ... 4 more
The error is misleading. You have provided a value that does not represent a complete URI
request = new HTTP gate ("trib.me/1lBFzSi");
This is a protocol unavailable.
Just provide a complete URI
request = new HttpGet ("http: // trib me / 1lBFzSi");
Comments
Post a Comment