470,599 Members | 1,465 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,599 developers. It's quick & easy.

I have a problem with commons-httpclient-3.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?
[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: Gecko/20070914 Firefox/");

HttpMethod method = null;

method = new GetMethod(url_name);
try {
} catch (HttpException e) {

} catch (IOException e) {

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

} catch (IOException e) {


/*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());
return responseBody;

Oct 13 '07 #1
0 1411

Post your reply

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

Similar topics

2 posts views Thread by Jon Dellaria | last post: by
1 post views Thread by Steven Mason | last post: by
reply views Thread by Joe Bloggs | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.