hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ghanchakkar <manojpras...@yahoo.com>
Subject Re: how 2 supress contentType when using multipartentity
Date Wed, 19 Mar 2008 01:42:30 GMT

Thanks Olegk.
In order to override the values I have derived my own class from file
FilePart and StringPart. I could not find any other way as these members are
private in FilePart and StringPart classes
Thanks for help.


olegk wrote:
> 
> 
> 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: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/how-2-supress-contentType-when-using-multipartentity-tp16098366p16135528.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