Dave, Daniel I am sorry if my previous statement turned out to be confusing or unclear. I do think that PostMethod may be more appropriate in your case. MultipartPostMethod usually comes handy when you need to submit binary data along with some parameters with a single HTTP request. In most cases, however simple HTTP POST (represented by PostMethod class) should suffice.
I suspect that the problem in your case lies with the server rather than with the client (I have no concrete evidence of that, though. It's just a guess on my part) What servlet engine are you using? If you are using Tomcat, what version? Are you sure it supports 'multipart/form-data' content type? Oleg -----Original Message----- From: Michael Becke [mailto:[EMAIL PROTECTED]] Sent: Dienstag, 28. Januar 2003 14:37 To: Commons HttpClient Project Subject: Re: MultipartPostMethod - Passing Parameters I think Oleg is saying that you use MultipartPostMethod in your example but should probably use PostMethod instead. Mike On Tuesday, January 28, 2003, at 07:52 AM, Dave Walsh wrote: > I saw your post and response, I have seen this guy alot on this forum. > I dod't myself know why we need a multipart form at this point, so if > it was omething that I said, ignore that for now. > > Dave > > Daniel Walsh wrote: > >> In trying to get to know the HttpClient component a bit, I attempted >> to write a simple program using a Java Servlet and the HttpClient API >> - the end result being that the client make a post to the servlet and >> the servlet return a brief HTML response to the client. The next >> step would be to transfer a file between the two, however, I'm >> running into some trouble with this first step. >> >> The only real requirements I've placed on this step is to use a post >> method instead of a get (because future steps would not be able to >> use a get), and to pass a parameter in the request. The parameter is >> where my problems start. After checking for this parameter on the >> server side, I throw an exception if it is non-existent. This is as >> far as the program has been running for me. >> I'm using HTTP Client 2.0 Alpha 2, and Commons Logging 1.0.2. I've >> included a couple of example classes that represent the basics of my >> code, and the thrown exception, in case anyone might have an idea as >> to what I am doing wrong: >> >> ______________________________________________________________________ >> ___________________________ >> >> CLIENT CLASS - >> >> >> import org.apache.commons.httpclient.*; >> import org.apache.commons.httpclient.methods.*; >> >> import java.io.*; >> import java.net.*; >> >> public class HttpClientExmpl >> { >> >> public HttpClientExmpl() >> { >> init(); >> } >> >> public void init() >> { >> MultipartPostMethod postMethod = new MultipartPostMethod(); >> postMethod.setPath("/servlet/HttpClientExmplServlet"); >> postMethod.addParameter("param-name", "param-value"); >> HttpClient client = new HttpClient(); >> HostConfiguration hostConfig = new HostConfiguration(); >> hostConfig.setHost("localhost", 8081, "http"); >> client.setConnectionTimeout(30000); >> client.setHostConfiguration(hostConfig); >> >> try >> { >> client.executeMethod(postMethod); >> } >> catch(HttpException httpEx) >> { >> httpEx.printStackTrace(); >> } >> catch(IOException ioEx) >> { >> ioEx.printStackTrace(); >> } >> String responseString = >> postMethod.getResponseBodyAsString(); >> postMethod.releaseConnection(); >> System.out.println(responseString); >> } >> public static void main(String args[]) >> { >> new HttpClientExmpl(); >> } >> } >> >> >> ______________________________________________________________________ >> ___________________________ >> >> SERVLET CLASS - >> >> import javax.servlet.*; >> import javax.servlet.http.*; >> >> import java.io.*; >> >> public class HttpClientExmplServlet extends HttpServlet >> { >> public void doPost(HttpServletRequest request, >> HttpServletResponse response) throws ServletException, IOException >> { >> String paramValue = request.getParameter("param-name"); >> if(paramValue == null) >> throw new ServletException(new NullPointerException("The >> getParameter call returned null.")); >> >> response.setContentType("text/html"); >> PrintWriter writer = response.getWriter(); >> StringBuffer buf = new StringBuffer(); >> buf.append("<HTML>\n"); >> buf.append("<HEAD>\n<TITLE>HTTP Client Example >> Application</TITLE>\n</HEAD>\n"); >> buf.append("<BODY>\n"); >> buf.append("The servlet received the parameter sent within the >> post method.\n"); >> buf.append("</BODY>\n"); >> buf.append("</HTML>"); >> >> writer.write(buf.toString()); >> writer.flush(); >> writer.close(); >> } >> } >> >> ______________________________________________________________________ >> ___________________________ >> >> RESULTING EXCEPTION - >> >> 2003-01-27 21:08:27 StandardWrapperValve[HttpClientExmplServlet]: >> Servlet.service() for servlet HttpClientExmplServlet threw exception >> java.lang.NullPointerException: The getParameter call returned null. >> at >> HttpClientExmplServlet.doPost(HttpClientExmplServlet.java:14) >> at javax.servlet.http.HttpServlet.service(HttpServlet.java:760) >> at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) >> at >> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appli >> cationFilterChain.java:247) >> at >> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFi >> lterChain.java:193) >> at >> org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(Monitor >> Filter.java:223) >> at >> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appli >> cationFilterChain.java:213) >> at >> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFi >> lterChain.java:193) >> at >> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperVa >> lve.java:243) >> at >> org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline. >> java:566) >> at >> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java >> :472) >> at >> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943) >> at >> org.apache.catalina.core.StandardContextValve.invoke(StandardContextVa >> lve.java:190) >> at >> org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline. >> java:566) >> at >> org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve. >> java:246) >> at >> org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline. >> java:564) >> at >> org.netbeans.modules.web.monitor.catalina.MonitorValve.invoke(MonitorV >> alve.java:142) >> at >> org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline. >> java:564) >> at >> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java >> :472) >> at >> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943) >> at >> org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2 >> 347) >> at >> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.ja >> va:180) >> at >> org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline. >> java:566) >> at >> org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcher >> Valve.java:170) >> at >> org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline. >> java:564) >> at >> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.ja >> va:170) >> at >> org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline. >> java:564) >> at >> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:4 >> 68) >> at >> org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline. >> java:564) >> at >> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java >> :472) >> at >> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943) >> at >> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValv >> e.java:174) >> at >> org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline. >> java:566) >> at >> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java >> :472) >> at >> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943) >> at >> org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor >> .java:1027) >> at >> org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.jav >> a:1125) >> at java.lang.Thread.run(Thread.java:536) >> >> >> >> Any suggestions would be greatly appreciated. >> >> Thanks, >> >> Daniel >> >> p.s. I'm not even sure that MultipartPostMethod is the most suitable >> object for this. If not, I'd appreciate a point in the right >> direction. >> >> > > > > -- > To unsubscribe, e-mail: > <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: > <mailto:[EMAIL PROTECTED]> > -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
