Results 1 to 3 of 3

Thread: missing info

  1. #1
    java-noob is offline Member
    Join Date
    Apr 2010
    Posts
    1
    Rep Power
    0

    Default 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();
    }
    }

  2. #2
    sonny's Avatar
    sonny is offline Senior Member
    Join Date
    Feb 2010
    Location
    North West England
    Posts
    146
    Rep Power
    0

    Default

    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

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default

    Quote Originally Posted by sonny View Post
    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;)
    Take it from me, experience possibly makes it worse. You get used to spotting the flow of code based on formatting, so unformatted code simply looks like white-noise to me...:)

Similar Threads

  1. Help; Missing JButtons
    By Cyprusice in forum New To Java
    Replies: 3
    Last Post: 01-10-2010, 11:50 PM
  2. IProgessMonitor missing in 3.4?
    By aznboarder in forum Eclipse
    Replies: 1
    Last Post: 03-19-2009, 11:29 PM
  3. Missing Elements
    By princess in forum NetBeans
    Replies: 1
    Last Post: 10-29-2008, 11:51 PM
  4. Missing a constructor?
    By kenny607 in forum New To Java
    Replies: 3
    Last Post: 10-24-2008, 10:55 AM
  5. is it bug? or am i missing a point?
    By blowguy in forum Threads and Synchronization
    Replies: 1
    Last Post: 11-20-2007, 06:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •