Results 1 to 3 of 3
Thread: missing info
- 04-19-2010, 08:39 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 1
- Rep Power
- 0
missing info
Here's a method that is missing some info. Can you please suggest me where to fix it?
Thanks,
Jn
public static String postDataMultiPart(String postdata, String url,String
postfiles,String fileparmname,String contenttype) throws Exception
{
String result="";
InputStream isr=null;
HttpClient client = new HttpClient();
PostMethod filePost = new PostMethod(url);
Part[] parts;
try
{
String[] parms = postdata.split("&");
parts = new Part[parms.length+1];
int i=0;
for (StringTokenizer iter = new StringTokenizer(postdata, "&");
iter.hasMoreElements();/*-*/) {
String pair = (String) iter.nextToken();
int split = pair.indexOf('=');
if (split <= 0) {
throw new Exception("Post Form invalid parms excepiont" + url + "?" + postdata);
}
else {
String key = pair.substring(0, split);
String value = pair.substring(split + 1);
///add to post parms now
parts[i] = new StringPart(key, value);
i++;
// filePost.addParameter(key, value);
}
}
parts[i]= new FilePart(fileparmname,new File(postfiles),contenttype, "UTF-8");
filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));
int status = client.executeMethod(filePost);
if(isr!=null)
{
BufferedReader rd = new BufferedReader(new InputStreamReader(isr));
StringBuffer sb = new StringBuffer();
String line;
while ((line = rd.readLine()) != null)
{
sb.append(line + "\n");
}
rd.close();
result = sb.toString();
}
}
catch (ProtocolException e)
{
throw new Exception("Post Form excepiont" + url + "?" + postdata, e);
}
finally
{
if(isr!=null)
{
isr.close();
}
filePost.releaseConnection();
}
}
- 04-19-2010, 10:00 PM #2
hi there,,
it would help if you edit your post and repaste the code using code tags..
it makes it much easier to read especially for the less experienced of us;)
Java Forums - BB Code List explains how
plus what specifically are you trying to do,
what is it doing wrong,, or what should it do
another useful link!
How To Ask Questions The Smart Way
kind regards
Sonny:p I still have my "L" plates on...... directions and explanations are far more help than blaring your Horn! :p Watching:CS106a on YouTube \Reading The Art & Science of Java by Eric S Roberts
- 04-20-2010, 09:55 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Similar Threads
-
Help; Missing JButtons
By Cyprusice in forum New To JavaReplies: 3Last Post: 01-10-2010, 11:50 PM -
IProgessMonitor missing in 3.4?
By aznboarder in forum EclipseReplies: 1Last Post: 03-19-2009, 11:29 PM -
Missing Elements
By princess in forum NetBeansReplies: 1Last Post: 10-29-2008, 11:51 PM -
Missing a constructor?
By kenny607 in forum New To JavaReplies: 3Last Post: 10-24-2008, 10:55 AM -
is it bug? or am i missing a point?
By blowguy in forum Threads and SynchronizationReplies: 1Last Post: 11-20-2007, 06:19 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks