On Mon, 2008-03-17 at 11:30 -0700, ghanchakkar wrote: > Please help me. > I building a bot and trying to upload file along with form fields. when > compare the request generated by httpclient with that of microsoft browser, > I notice that httpclient is having following format after the header. > -------------------------------boundaryid > Content-Disposition: form-data; name="fieldname1" > Content-Type: text/plain; charset=UTF-8 > Content-Transfer-Encoding: 8bit > > value1 > -------------------------------boundaryid > Content-Disposition: form-data; name="fieldname2" > Content-Type: text/plain; charset=UTF-8 > Content-Transfer-Encoding: 8bit > > value2 > -------------------------------boundaryid > : > : > > But internet explorer generates request in following format > -------------------------------boundaryid > Content-Disposition: form-data; name="fieldname1" > > value1 > -------------------------------boundaryid > Content-Disposition: form-data; name="fieldname2" > > value2 > -------------------------------boundaryid > : > : > > Notice the Content-Type and Content-Transfer-Encoding fields are populated > by HttpClient. > The webserver is not expecting these two fields
Then the webserver is buggy. > and therefore throwing me an > error as it is not able to trace the value for the required formfield (I > guess it is poorly written server) > > How do I get rid of these extra two values while using httpclient > multipartentity. Set them to null. Hope this helps. Oleg > please see snippet of my code below > > Part[] parts = new Part[files.length + nvPairs.length]; > > //setup form fields > for(int i = 0 ; i < nvPairs.length ; i++){ > parts[i] = new StringPart(nvPairs[i].getName(), > nvPairs[i].getValue(),CHAR_SET); > } > //setup files > for(int i = nvPairs.length, j=0 ; j < files.length ; j++,i++){ > File targetFile = new File(files[j].getValue()); > parts[i] = new FilePart(files[j].getValue(), targetFile); > } > > post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams())); > > httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000); > > statusCode = httpClient.executeMethod(post); > > > > Please help ASAP. > > Thanks in advance. > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]