400 error with HttpClient for a link with an anchor

前端 未结 4 1501
死守一世寂寞
死守一世寂寞 2021-01-17 03:15

Here is my code:

DefaultHttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
HttpResponse response = client.execute(request);
         


        
4条回答
  •  情话喂你
    2021-01-17 03:52

    String user_url2="uhttp://www.somedomain.com/somedirectory/somepage#someanchor";

        HttpClient client = new DefaultHttpClient();
        HttpGet siteRequest = new HttpGet(user_url2);
        StringBuilder sb = new StringBuilder();
    
        HttpResponse httpResponse;
    
        try {
            httpResponse = client.execute(siteRequest);
            HttpEntity entity = httpResponse.getEntity();
            InputStream in = entity.getContent();
    
            String line = null;
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(in));
            while ((line = reader.readLine()) != null)
    
            {
    
                sb.append(line);
    
            }
    
            result = sb.toString();
    

    result string will display url value

提交回复
热议问题