Results 1 to 3 of 3
  1. #1
    fowell is offline Member
    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Default HTTPClient Error

    Hi,

    Im learning HTTPClient, Im trying to get content from an URL but is imposible Im going crazy.

    URL is: [Moderator edit: link removed]

    Always return same error:
    Java Code:
    org.apache.http.NoHttpResponseException: The target server failed to respond
            at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:95) ~[httpclient-4.2.2.jar:4.2.2]
            at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:62) ~[httpclient-4.2.2.jar:4.2.2]
            at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:254) ~[httpcore-4.2.2.jar:4.2.2]
            at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:289) ~[httpcore-4.2.2.jar:4.2.2]
            at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:252) ~[httpclient-4.2.2.jar:4.2.2]
            at org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader(ManagedClientConnectionImpl.java:191) ~[httpclient-4.2.2.jar:4.2.2]
            at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:300) ~[httpcore-4.2.2.jar:4.2.2]
            at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:127) ~[httpcore-4.2.2.jar:4.2.2]
            at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:712) ~[httpclient-4.2.2.jar:4.2.2]
            at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:517) ~[httpclient-4.2.2.jar:4.2.2]
            at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906) ~[httpclient-4.2.2.jar:4.2.2]
            at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805) ~[httpclient-4.2.2.jar:4.2.2]
            at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784) ~[httpclient-4.2.2.jar:4.2.2]
            at com.fowellsoft.util.http.HttpClientManager.executeGetMethod(HttpClientManager.java:128) ~[bin/:na]
            at com.fowellsoft.test.launcher.LauncherTest.getSegundaManoTest(LauncherTest.java:68) [bin/:na]
            at com.fowellsoft.test.launcher.LauncherTest.main(LauncherTest.java:31) [bin/:na]
    ----------------------------------------------------

    Java Code:
    	public String executeGetMethod(String protocol, String host, String path, List<KeyValue> params)
    	{
    		if(log.isDebugEnabled())
    		{ log.debug("Comienza peticion get para la url: {} con protocol: {}", host, protocol); }
    		
    		
    		String result = null;
    		InputStream inputStream = null;
    		
    		try
    		{
    			if(isValidURL(protocol, host))
    			{
    				URIBuilder uriBuilder = new URIBuilder();
    				uriBuilder.setScheme(protocol);
    				uriBuilder.setHost(host);
    				if(StringUtils.isNotBlank(path)){ uriBuilder.setPath(path); }
    				
    				if(params != null)
    				{
    					for(KeyValue keyValue : params)
    					{
    						uriBuilder.addParameter((String)keyValue.getKey(), (String)keyValue.getValue());
    					}
    				}
    				
    				httpClient.setKeepAliveStrategy(new SpecificConnectionKeepAliveStrategy());
    				
    				HttpGet httpGet = new HttpGet(uriBuilder.build());
    				HttpResponse response = httpClient.execute(httpGet);
    				
    				int statusCode = response.getStatusLine().getStatusCode();
    				log.debug("Status code: {}", statusCode);
    				
    				
    				HttpEntity entity = response.getEntity();
    				inputStream = entity.getContent();
    				result = convertStreamToString(inputStream);
    			}
    		}
    		catch(URISyntaxException urise)
    		{
    			log.error("Error: ", urise);
    		}
    		catch(ClientProtocolException cpe)
    		{
    			log.error("Error: ", cpe);
    		}
    		catch(IOException ioe)
    		{
    			log.error("Error: ", ioe);
    		}
    		finally
    		{
    			try
    			{
    				if(inputStream != null) 
    					inputStream.close();
    			}
    			catch(IOException ioe){}
    		}
    		
    		return result;
    	}
    Im testing other URLs and works fine, but...this is posible.

    Anybody can help me?
    Thanks
    Last edited by DarrylBurke; 12-17-2012 at 02:11 PM. Reason: Removed spammy link

  2. #2
    fowell is offline Member
    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Default Re: HTTPClient Error

    Nobody can help me?
    Its very important for me!!!

    Thanks

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: HTTPClient Error

    I'd look at the traffic when you go to that website, using a browser that lets you see what the message flow is like.
    Please do not ask for code as refusal often offends.

Similar Threads

  1. ERROR WHILE USING HttpClient CLASS
    By ROBANALYTICS in forum Advanced Java
    Replies: 0
    Last Post: 11-06-2011, 09:27 AM
  2. Proxy authentication using HttpClient 4.0.3
    By Jsharma in forum Advanced Java
    Replies: 0
    Last Post: 01-21-2011, 03:33 AM
  3. Using HttpClient
    By jdetloff in forum New To Java
    Replies: 4
    Last Post: 01-06-2010, 10:43 AM
  4. Using HttpClient with Eclipse
    By jdetloff in forum Eclipse
    Replies: 4
    Last Post: 01-06-2010, 09:47 AM
  5. HttpClient invalid headers
    By Nicole in forum Advanced Java
    Replies: 6
    Last Post: 03-31-2009, 12:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •