Hi Oleg,
Here is the sample code which I am trying to get the search results
String host = "www.tkdl.res.in";
String searchURI = "/tkdl/langdefault/common/TKDLSearch.asp?GL=Eng";
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(
new AuthScope("172.31.100.14", 3128),
new UsernamePasswordCredentials("user", "pass"));
HttpHost targetHost = new HttpHost(host);
HttpHost proxy = new HttpHost("172.31.100.14", 3128);
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
proxy);
httpclient.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS,
false);
HttpPost httpPost = new HttpPost(searchURI);
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("SearchString", keyword));
try {
httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
HttpResponse response = null;
HttpEntity entity = null;
try {
response = httpclient.execute(targetHost, httpPost);
entity = response.getEntity();
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
if (entity != null) {
System.out.println("Response content length: " +
entity.getContentLength());
entity.writeTo(System.out);
}
if (entity != null) {
entity.consumeContent();
}
}
catch (ClientProtocolException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
Please tell me what went wrong in it.
On Sat, Apr 24, 2010 at 10:30 AM, Phani Sajja <[email protected]> wrote:
> Hi Oleg,
> can you give me the sample code that works for you.
>
>
> On Fri, Apr 23, 2010 at 6:07 PM, Oleg Kalnichevski <[email protected]>wrote:
>
>> On Fri, 2010-04-23 at 17:01 +0530, Phani Sajja wrote:
>> > Hi Oleg,
>> > Here is the complete log
>> >
>>
>> Works without any problem for me
>>
>> [DEBUG] SingleClientConnManager - Get connection for route
>> HttpRoute[{}->http://www.tkdl.res.in]
>> [DEBUG] DefaultHttpClient - Attempt 1 to execute request
>> [DEBUG] DefaultClientConnection - Sending request:
>> GET /tkdl/langdefault/common/home.asp/ HTTP/1.1
>> [DEBUG] headers - >> GET /tkdl/langdefault/common/home.asp/ HTTP/1.1
>> [DEBUG] headers - >> Host: www.tkdl.res.in
>> [DEBUG] headers - >> Connection: Keep-Alive
>> [DEBUG] headers - >> User-Agent: Apache-HttpClient/4.0.1 (java 1.5)
>> [DEBUG] DefaultClientConnection - Receiving response: HTTP/1.1 302
>> Object moved
>> [DEBUG] headers - << HTTP/1.1 302 Object moved
>> [DEBUG] headers - << Connection: close
>> [DEBUG] headers - << Date: Fri, 23 Apr 2010 12:38:42 GMT
>> [DEBUG] headers - << Server: Microsoft-IIS/6.0
>> [DEBUG] headers - << X-Powered-By: ASP.NET
>> [DEBUG] headers - <<
>> Location: /tkdl/includes/errhandler/myeh_500-100.asp?404;
>> http://www.tkdl.res.in/tkdl/langdefault/common/home.asp/
>> [DEBUG] DefaultRedirectHandler - Redirect requested to location
>> '/tkdl/includes/errhandler/myeh_500-100.asp?404;
>> http://www.tkdl.res.in/tkdl/langdefault/common/home.asp/'
>> [DEBUG] DefaultHttpClient - Redirecting to
>> '
>> http://www.tkdl.res.in/tkdl/includes/errhandler/myeh_500-100.asp?404;http://www.tkdl.res.in/tkdl/langdefault/common/home.asp/'
>> via HttpRoute[{}->http://www.tkdl.res.in]
>> [DEBUG] DefaultClientConnection - Connection closed
>> [DEBUG] DefaultHttpClient - Attempt 2 to execute request
>> [DEBUG] DefaultClientConnection - Sending request:
>> GET /tkdl/includes/errhandler/myeh_500-100.asp?404;
>> http://www.tkdl.res.in/tkdl/langdefault/common/home.asp/ HTTP/1.1
>> [DEBUG] headers - >>
>> GET /tkdl/includes/errhandler/myeh_500-100.asp?404;
>> http://www.tkdl.res.in/tkdl/langdefault/common/home.asp/ HTTP/1.1
>> [DEBUG] headers - >> Host: www.tkdl.res.in
>> [DEBUG] headers - >> Connection: Keep-Alive
>> [DEBUG] headers - >> User-Agent: Apache-HttpClient/4.0.1 (java 1.5)
>> [DEBUG] DefaultClientConnection - Receiving response: HTTP/1.1 200 OK
>> [DEBUG] headers - << HTTP/1.1 200 OK
>> [DEBUG] headers - << Date: Fri, 23 Apr 2010 12:38:42 GMT
>> [DEBUG] headers - << Server: Microsoft-IIS/6.0
>> [DEBUG] headers - << X-Powered-By: ASP.NET
>> [DEBUG] headers - << Content-Length: 3413
>> [DEBUG] headers - << Content-Type: text/html
>> [DEBUG] headers - << Set-Cookie:
>> ASPSESSIONIDCSDTRRCT=HHKHPPKADJGPLFGHFDHKCMDH; path=/
>> [DEBUG] headers - << Cache-control: private
>> [DEBUG] DefaultHttpClient - Connection can be kept alive indefinitely
>>
>>
>>
>> > 16:50:57,953 DEBUG SingleClientConnManager:195 - Get connection for
>> route
>> > HttpRoute[{}->http://172.31.100.14:3128->
>> > http://www.tkdl.res.in/tkdl/langdefault/common/home.asp]
>>
>> You have mis-configured HttpClient because it obviously tries to connect
>> to an invalid host
>>
>> http://www.tkdl.res.in/tkdl/langdefault/common/home.asp is not a host,
>> it is a URL.
>>
>> Oleg
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
>
>
> --
> Regards
> Phani. S
>
>
--
Regards
Phani. S