Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

org.apache.commons.httpclient.URIException: URI-Reference required

807589Nov 14 2008 — edited Nov 14 2008
Hi,

I have this code
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.URI;
import org.apache.commons.httpclient.methods.PostMethod;

/**
 * Testing application connecting to secured web page.
 *
 * @author Pavel Halas
 *
 */
public class Test {
	
	private final static String CMc2_Terminal = "0000-TODOS";
	private final static String CMc2_Fecha1 = "01/08/2008";
	private final static String CMc2_Fecha2 = "30/08/2008";
	private final static String mAdua = "118";
	private final static String CMc2_DNave = "";

    public static void main(String[] args) {
        HttpClient client = new HttpClient();

        // connect to a login page to retrieve session ID
        PostMethod method = new PostMethod("http://www.aduanet.gob.pe/servlet/CRManFLlega");

        // post auth information with it
        method.addRequestHeader("Cookie", "x=y");
        method.addParameter("mAdua", mAdua);
        method.addParameter("CMc2_Terminal", CMc2_Terminal);
        method.addParameter("CMc2_Fecha1", CMc2_Fecha1);
		method.addParameter("CMc2_Fecha2", CMc2_Fecha2);
		method.addParameter("CMc2_DNave", CMc2_DNave);


        try {
            client.executeMethod(method);

            String redirectLocation = null;
            Header locationHeader = method.getResponseHeader("location");
            if (locationHeader != null) {
                redirectLocation = locationHeader.getValue();
            } else {
                // The response is invalid and did not provide the new location for
                // the resource. Report an error or possibly handle the response
                // like a 404 Not Found error.
                method.getResponseBodyAsString();
            }
            method.setURI(new URI(redirectLocation, true));
            client.executeMethod(method);

            // store the session info for the next call
            Header[] headers = method.getResponseHeaders();

            Thread.sleep(2000);

            // connect to a page you're interested...
            //PostMethod getMethod = new PostMethod("http://secured.web.page/content.html");

            // ...using the session ID retrieved before
           /* for (Header header : headers) {
                getMethod.setRequestHeader(header);
            }*/
            client.executeMethod(method);

            // log the page source
            System.out.println(method.getResponseBodyAsString());
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}
and I dont know why apears this error
org.apache.commons.httpclient.URIException: URI-Reference required
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 12 2008
Added on Nov 14 2008
1 comment
1,951 views