473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

I have a problem with commons-httpclient-3.1.

1
I have a problem with commons-httpclient-3.1.
When i try to get some page, cookies do not come to me.
There is no error or exception message. Just null text.
What could you advise me?
Code:
[PHP]import java.net.*;
import java.io.*;
import java.util.*;

import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.DefaultHttpMethodRet ryHandler;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.HttpVersion;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.SimpleHttpConnection Manager;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.cookie.CookieSpec;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpClientPar ams;
import org.apache.commons.httpclient.params.HttpMethodPar ams;
import org.apache.commons.httpclient.params.HttpParams;




public class GetUrl {
private Cookie[] CookieString;
HttpClient client = new HttpClient();
HttpClientParams params = new HttpClientParams();
HttpState initialState = new HttpState();
public GetUrl()
{


}
public String get(String url_name)
{

params.setParameter(HttpMethodParams.USER_AGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7");
params.setCookiePolicy(CookiePolicy.DEFAULT);

initialState.addCookies(CookieString);
client.setState(initialState);
client.setParams(params);
HttpMethod method = null;

method = new GetMethod(url_name);
method.setFollowRedirects(true);
try {
client.executeMethod(method);
} catch (HttpException e) {

e.printStackTrace();
} catch (IOException e) {

e.printStackTrace();
}
String responseBody = null;
try {
responseBody = method.getResponseBodyAsString();


} catch (IOException e) {

e.printStackTrace();
}

/*System.out.println("Present cookies: ");
for (int i = 0; i < header.length; i++) {
System.out.println(" - " + header[i].getName());
}*/
CookieString = initialState.getCookies();
// Display the cookies
System.out.println("Present cookies: ");
for (int i = 0; i < CookieString.length; i++) {
System.out.println(" - " + CookieString[i].toExternalForm());
}
System.out.println(responseBody);
return responseBody;
}




}[/PHP]
Oct 13 '07 #1
0 1545

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jon Dellaria | last post by:
I have been using MySql as the database using JSP's and JavaBeans but recently I have wanted to start using the database connection pooling mechanism built into TomCat. I think I am having a...
1
by: Steven Mason | last post by:
Here's my problem. I've certain jar files I've included in my classpath that I need to work with. I've included these in my path variable so when I type path at the command line I get : ...
0
by: Gary Smart | last post by:
Hello. I've been searching news groups and apache and google, but can't solve this one: I have an XML file used to create menu items in a Swing UI. I have a <menu> element that can have an...
0
by: Joe Bloggs | last post by:
Hi all, I take the pleasure to inform that Dotnet Commons Logging has been released for use. Dotnet Commons Logging, a subproject of the Donet Commons project currently located under the...
0
by: Miha Valencic | last post by:
Hi! WS is written in java in I am consuming it with .net (v1.1) client. The problem is in Soap fault exception (below). The program returns exception: Unhandled Exception:...
0
by: cwho.work | last post by:
Hi! We are using apache ibatis with our MySQL 5.0 database (using innodb tables), in our web application running on Tomcat 5. Recently we started getting a number of errors relating to...
0
by: AshishMishra16 | last post by:
Hi friends, Does somebody has a example for file upload using Jakarta Commons? Please post it here in reply.
3
by: JMcCrillis | last post by:
I've implemented a FileUpload servlet using AJAX and JS. It appears to be working well but for one issue. I used XMLHTTP so I could intercept the response in Javascript and write it out to a field...
3
KevinADC
by: KevinADC | last post by:
If you are entirely unfamiliar with using Perl to sort data, read the "Sorting Data with Perl - Part One and Two" articles before reading this article. Beginning Perl coders may find this article...
7
by: ne0lithic | last post by:
Dear all, I'm developing a servlet to handle file upload requests. Despite importing all required classes in the build path, I still receive the 'classNotFoundException' for FileItemFactory. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.