hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ghanchakkar <manojpras...@yahoo.com>
Subject how 2 supress contentType when using multipartentity
Date Mon, 17 Mar 2008 20:57:13 GMT

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 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. 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. 


-- 
View this message in context: http://www.nabble.com/how-2-supress-contentType-when-using-multipartentity-tp16098366p16098366.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message