Hi
I am trying to write a java client to a HTTP server. All I want to do is send a
text input field with a value and a file attachment to the web server.
I tried to simulate what the browser would do when the user clicks on the submit
button on the form. I created the format that the server would
receive the data in and sent it as a datastream to the server. However I keep
receiving the error:
java.io.IOException: Posted content type isn't multipart/form-data
at
com.oreilly.servlet.MultipartRequest.readRequest(MultipartRequest.java:339)
at com.oreilly.servlet.MultipartRequest.<init>(MultipartRequest.java:149)
at UploadTest2.doPost(UploadTest2.java:24)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:521)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:588)
at
lotus.domino.servlet.DominoServletInvoker.executeServlet(DominoServletInvoker.java:266)
at
lotus.domino.servlet.DominoServletInvoker.service(DominoServletInvoker.java:212)
at lotus.domino.servlet.ServletManager.service(ServletManager.java:235)
On the server side I have the program written using mulitpartrequest class (from
the OReilly package) which completes the file upload and prints the file
contents.
This server programs works if I use html and submit the form via the broswer. I
am unable to simulate the same using a java client program.
Can anyone give me any pointers.
I went through the RFC 1867 that talks about File upload in HTML to understand
the format that the server would receive the data in and am following it
Could any one shed any light on it. Am I attempting something very complex or am
I not using the java.net package appropriately ?
The format that I am using to simulate the browser submit is :
out = new DataOutputStream(urlConn.getOutputStream());
String content=
"POST http://myjavaserver/servlet/UploadTest2 HTTP/1.0" + "\n" +
"Referer:''" + "\n" +
"Connection:Keep-Alive" + "\n" +
"User-Agent:Mozilla/3.01Gold (Win NT;U)" + "\n" +
"Host:myjavaserver" + "\n" +
"Accept:*/*" + "\n" +
"Content-type:multipart/form-data;boundary=___________________________29312135143216"
+ "\n" +
"Content-length:313" + "\n\n" +
"_____________________________29312135143216" + "\n\n" +
"Content-disposition:form-data; name='done'" + "\n\n" +
"SubmitQuery" + "\n" +
"_____________________________29312135143216" + "\n\n" +
"Content-disposition:form-data; name='thefile';filename='c:\\temp\\hi.txt'" +
"\n" +
"Content-Type:text/plain" + "\n\n" +
"hi there" + "\n" +
"_____________________________29312135143216" + "\n" ;
out.writeBytes(content);
Thanks,
Rajesh Shedde
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html