Hello, 


    I am developing an application where, I have to login to web site, etc.
I can access the web page, retreive the page. So, GET part is working fine.
I have problem with Post. I am using JDK 1.6 with apache's HttpClient 3.1
for communicating through the web site. After setting parameters in
NameValuePair[], when i run execuseMethod(postMethod), it throws the
following exception :

[i]Exception in thread "AWT-EventQueue-0"
java.lang.IllegalArgumentException: host parameter is null
        at
org.apache.commons.httpclient.HttpConnection.setHost(HttpConnection.java:248)
        at
org.apache.commons.httpclient.SimpleHttpConnectionManager.getConnectionWithTimeout
(SimpleHttpConnectionManager.java:163)
        at org.apache.commons.httpclient.HttpMethodDirector.executeMethod
(HttpMethodDirector.java:152)
        at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
        at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
        at ynamemaker.YnameClient.POST(YnameClient.java:395)
        at ynamemaker.YnameClient.createAccount(YnameClient.java:325)
        at
ynamemaker.YAccCreatorForm.start_btnMouseClicked(YAccCreatorForm.java:97)
        at ynamemaker.YAccCreatorForm.access$000(YAccCreatorForm.java:14)
        at
ynamemaker.YAccCreatorForm$1.mouseClicked(YAccCreatorForm.java:42)
        at
java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
        at java.awt.Component.processMouseEvent(Component.java:6041)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
        at java.awt.Component.processEvent(Component.java:5803)
        at java.awt.Container.processEvent(Container.java:2058)
        at java.awt.Component.dispatchEventImpl(Component.java:4410)
        at java.awt.Container.dispatchEventImpl(Container.java:2116)
        at java.awt.Component.dispatchEvent(Component.java:4240)
        at
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
        at
java.awt.LightweightDispatcher.processMouseEvent(Container.java:3995)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
        at java.awt.Container.dispatchEventImpl(Container.java:2102)
        at java.awt.Window.dispatchEventImpl(Window.java:2429)
        at java.awt.Component.dispatchEvent(Component.java:4240)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
        at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy

(EventDispatchThread.java:173)
        at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
        at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
        at
java.awt.EventDispatchThread.run(EventDispatchThread.java:121)[/i]


     My post code is as follows:
    public String POST(String url, NameValuePair[] data) {
        String res = "";
        PostMethod method = new PostMethod(url);
        // SET PROPERTIES 
        method.getParams().setParameter("http.method.retry-handler", new
DefaultHttpMethodRetryHandler(3, false));
        method.setRequestHeader("User-agent", USER_AGENT);
        method.setRequestHeader("Accept", ACCEPT);
        method.setRequestHeader("Accept-Language", ACCEPT_LANG);
        method.setRequestHeader("Accept-Charset", USER_AGENT);
        method.setRequestHeader("Keep-Alive", KEEP_ALIVE);
        method.setRequestHeader("Connection", CONNECTION);

        method.setRequestBody(data);
        int statusCode = 0;
        try {
            statusCode = client.executeMethod(method);  // EXCEPTION IS
THROWN
        }catch (IOException ie) {
            method.releaseConnection();
            System.out.println("Error Exe Method - Post. Status Code = " +
statusCode);
            ie.printStackTrace();
        }

        I went across the For Absolute Beginners :-      
http://jakarta.apache.org/httpcomponents/httpclient-3.x/logging.html site.
Grasped & corrected how much I understood. After this, I am not able to
figure out the problem.  
         Can any one PLEASE help me with this error. Any help is highly
appreciated. How can I know if the headers are wrong, or any extra
parameters need to be added, etc ? Can that be the reason for failure?


Thanks

Terry
-- 
View this message in context: 
http://www.nabble.com/Error-Post-a-form-tf4835421.html#a13833727
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to