Hi Folks,

Please disregard the previous message. I see now that the correct way is:

requestContent.addPart("email", new StringBody("[email protected] ));
requestContent.addPart("password", new StringBody("xxxx"));

without the URLEncode.

-s

On May 21, 2009, at 10:04 PM, Shawn Van Every wrote:

Greetings,

I have the following code working. It simulates a file upload through a browser of XML data and the rest of the form elements as GET variables. The problem is that the service that I will be using in the end doesn't support GET variables and instead only allows for normal POST variables. Unfortunately I can't figure out how to include normal form post variables in a MultipartEntity. Any help would be appreciated.

                 DefaultHttpClient client = new DefaultHttpClient();
client.getParams().setBooleanParameter("http.protocol.expect- continue", false);

String xmldata = "<table><row><field name=\"test\">1</ field></row></table>";
                 byte[] data = xmldata.getBytes();
                 InputStream ins = new ByteArrayInputStream(data);
InputStreamBody filePartBoday = new InputStreamBody(ins, "data.xml"); String encodedVars = "email=" + URLEncoder.encode("[email protected] ") + "&password=" + "xxxx" + "&project_id=" + "565" + "&table_name=" + "test" + "&type=" + "xml";

                 MultipartEntity requestContent = new MultipartEntity();
                 requestContent.addPart("data_file", filePartBoday);

ResponseHandler<String> responseHandler = new BasicResponseHandler(); HttpPost method = new HttpPost(new URI("http://server.org/upload.php? " + encodedVars));
                 method.setHeader("user-agent", "Some User Agent");
                 method.setEntity(requestContent);

                 String response = client.execute(method,responseHandler);      

I have tried this:
requestContent.addPart("form_data", new StringBody(encodedVars,"UTF-8")));

And this:
requestContent.addPart("email", new StringBody(URLEncoder.encode("vanev...@walking- productions.com","UTF-8"))); requestContent.addPart("password", new StringBody(URLEncoder.encode("xxxx","UTF-8"))); requestContent.addPart("type", new StringBody(URLEncoder.encode("xml","UTF-8"))); requestContent.addPart("project_id", new StringBody(URLEncoder.encode("565","UTF-8"))); requestContent.addPart("table_name", new StringBody(URLEncoder.encode("test")));
        
without success..

Thanks for any advice..

-shawn

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to