473,722 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I have a problem with commons-httpclient-3.1.

1 New Member
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.comm ons.httpclient. Cookie;
import org.apache.comm ons.httpclient. DefaultHttpMeth odRetryHandler;
import org.apache.comm ons.httpclient. Header;
import org.apache.comm ons.httpclient. HttpClient;
import org.apache.comm ons.httpclient. HttpException;
import org.apache.comm ons.httpclient. HttpMethod;
import org.apache.comm ons.httpclient. HttpState;
import org.apache.comm ons.httpclient. HttpStatus;
import org.apache.comm ons.httpclient. HttpVersion;
import org.apache.comm ons.httpclient. NameValuePair;
import org.apache.comm ons.httpclient. SimpleHttpConne ctionManager;
import org.apache.comm ons.httpclient. cookie.CookiePo licy;
import org.apache.comm ons.httpclient. cookie.CookieSp ec;
import org.apache.comm ons.httpclient. methods.GetMeth od;
import org.apache.comm ons.httpclient. methods.PostMet hod;
import org.apache.comm ons.httpclient. params.HttpClie ntParams;
import org.apache.comm ons.httpclient. params.HttpMeth odParams;
import org.apache.comm ons.httpclient. params.HttpPara ms;




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


}
public String get(String url_name)
{

params.setParam eter(HttpMethod Params.USER_AGE NT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7");
params.setCooki ePolicy(CookieP olicy.DEFAULT);

initialState.ad dCookies(Cookie String);
client.setState (initialState);
client.setParam s(params);
HttpMethod method = null;

method = new GetMethod(url_n ame);
method.setFollo wRedirects(true );
try {
client.executeM ethod(method);
} catch (HttpException e) {

e.printStackTra ce();
} catch (IOException e) {

e.printStackTra ce();
}
String responseBody = null;
try {
responseBody = method.getRespo nseBodyAsString ();


} catch (IOException e) {

e.printStackTra ce();
}

/*System.out.pri ntln("Present cookies: ");
for (int i = 0; i < header.length; i++) {
System.out.prin tln(" - " + header[i].getName());
}*/
CookieString = initialState.ge tCookies();
// Display the cookies
System.out.prin tln("Present cookies: ");
for (int i = 0; i < CookieString.le ngth; i++) {
System.out.prin tln(" - " + CookieString[i].toExternalForm ());
}
System.out.prin tln(responseBod y);
return responseBody;
}




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

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

Similar topics

2
4445
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 problem with defining my JDBC resource within Tomcat. I am pretty sure that my code is correct (but I am not certain), and the problem is with defining the resource in Tomcat. Has anyone done this before? Any advice would be helpful.
1
3209
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 : PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program...
0
1986
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 unlimited number of other <menu> elements. So for a menu structure like Tools|Options|Email, the XML would be similar to:
0
4660
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 GotDotNet Workspace, has been released as an individual package. Dotnet Commons Logging provides a unified Log interface that acts as a
0
1396
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: System.Xml.XmlException: 'Element' is an invalid node type. Line 12, position 4. If I move the <multiRef element within the soapenv:Fault element, it works. Is this parsing .net bug?? Help.
0
11701
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 java.sql.SQLException: Deadlock found when trying to get lock; Try restarting transaction message from server: "Lock wait timeout exceeded; try restarting transaction"; We get such errors generally on inserts or updates while applying a
0
1183
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
19048
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 on my webpage. I get back that my readyState is 4 and my status is 200 and status text is "OK", but my responseText is always empty. Both on FireFox and IE7, so it must be something I'm doing (wrong). I've also set up an IFRAME to redirect the...
3
7341
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 uses unfamiliar terms and syntax. Intermediate and advanced Perl coders should find this article useful. The object of the article is to inform the reader, it is not about how to code Perl or how to write good Perl code, but to teach the Schwartzian...
7
2534
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 have also included the file-upload library in the build path of my project. Does anyone know why this is happening? As you can see below I've done a lot of redundant importing as well hoping it would solve the problem but it hasn't. I've been trying to...
0
8867
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8740
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9386
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9158
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6685
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5996
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4764
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2606
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2148
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.