×

Discussion Board

Results 1 to 2 of 2

Thread: Multipart data

  1. #1
    Regular Contributor
    Join Date
    Jan 2006
    Posts
    90

    Multipart data

    Hi
    how can we post multipart data from midp? Which all properties should be set for the connection. i tried to post using the code below:


    conn.setRequestMethod(HttpConnection.POST);
    conn.setRequestProperty("user-agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
    String boundary = "---------------------------7d226f700d0"; conn.setRequestProperty("Content-Type","multipart/form-data; boundary=" + boundary);
    dos = new DataOutputStream(conn.openDataOutputStream());
    String s = "--" + boundary +"\r\n";
    dos.write(s.getBytes());
    System.out.println("s = "+s);
    writeParam("name", "julien", dos, boundary);
    writeParam("post", "stagiaire", dos, boundary);
    writeFile("file", "C:\\tmpfoo.txt",dos, boundary);
    dos.flush();



    private static void writeParam(String name, String value, DataOutputStream out, String boundary) {
    try {

    out.write(("content-disposition: form-data; name=\"" + name + "\"\r\n\r\n").getBytes());
    out.write((value).getBytes());
    out.write(("\r\n" + "--" + boundary + "\r\n").getBytes());
    } catch (Exception e) { System.out.println(e.toString()); }
    }


    private void writeFile(String name, String filePath, DataOutputStream out, String boundary)
    {
    try {
    out.write(("content-disposition: form-data; name=\"" + name + "\"; filename=\""
    + filePath + "\"\r\n").getBytes());
    out.write(("content-type: application/octet-stream" + "\r\n\r\n").getBytes());
    Class c = this.getClass();
    InputStream is = c.getResourceAsStream("/tmpfoo.txt");
    int length = is.available();
    while (true) {
    synchronized (buffer) {
    int amountRead = is.read(buffer);
    if (amountRead == -1) {
    break;
    }
    System.out.println("amount read = "+amountRead);
    out.write(buffer, 0, amountRead);
    }
    }
    //raw= new byte[length];


    out.write(("\r\n" + "--" + boundary + "\r\n").getBytes());
    }
    catch (Exception e)
    {
    System.out.println(e.toString());
    }
    }


    Data is reaching the server...but got an exception "java.io.IOException: Corrupt form data: premature ending".
    thanks in advance

  2. #2
    Registered User
    Join Date
    Mar 2008
    Posts
    4

    Re: Multipart data

    Quote Originally Posted by jini_1 View Post
    Hi
    how can we post multipart data from midp? Which all properties should be set for the connection. i tried to post using the code below:


    conn.setRequestMethod(HttpConnection.POST);
    conn.setRequestProperty("user-agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
    String boundary = "---------------------------7d226f700d0"; conn.setRequestProperty("Content-Type","multipart/form-data; boundary=" + boundary);
    dos = new DataOutputStream(conn.openDataOutputStream());
    String s = "--" + boundary +"\r\n";
    dos.write(s.getBytes());
    System.out.println("s = "+s);
    writeParam("name", "julien", dos, boundary);
    writeParam("post", "stagiaire", dos, boundary);
    writeFile("file", "C:\\tmpfoo.txt",dos, boundary);
    dos.flush();



    private static void writeParam(String name, String value, DataOutputStream out, String boundary) {
    try {

    out.write(("content-disposition: form-data; name=\"" + name + "\"\r\n\r\n").getBytes());
    out.write((value).getBytes());
    out.write(("\r\n" + "--" + boundary + "\r\n").getBytes());
    } catch (Exception e) { System.out.println(e.toString()); }
    }


    private void writeFile(String name, String filePath, DataOutputStream out, String boundary)
    {
    try {
    out.write(("content-disposition: form-data; name=\"" + name + "\"; filename=\""
    + filePath + "\"\r\n").getBytes());
    out.write(("content-type: application/octet-stream" + "\r\n\r\n").getBytes());
    Class c = this.getClass();
    InputStream is = c.getResourceAsStream("/tmpfoo.txt");
    int length = is.available();
    while (true) {
    synchronized (buffer) {
    int amountRead = is.read(buffer);
    if (amountRead == -1) {
    break;
    }
    System.out.println("amount read = "+amountRead);
    out.write(buffer, 0, amountRead);
    }
    }
    //raw= new byte[length];


    out.write(("\r\n" + "--" + boundary + "\r\n").getBytes());
    }
    catch (Exception e)
    {
    System.out.println(e.toString());
    }
    }


    Data is reaching the server...but got an exception "java.io.IOException: Corrupt form data: premature ending".
    thanks in advance

    Please give me solution for sending mutupart/form-data to server using symbian c++
    The solution has given in the "http://wiki.forum.nokia.com/index.php/Symbian_C%2B%2B_:_Multipart/form-data" but the file is not received in the server.

    Please help me if anybody has the solution for this

Similar Threads

  1. suckho, i have encontered the same problems. Could you tell me how you resolved it?
    By dicson_hu in forum Symbian Networking & Messaging (Closed)
    Replies: 4
    Last Post: 2005-12-09, 10:56
  2. GPRS connection problems on 6600..
    By suckho in forum Symbian Networking & Messaging (Closed)
    Replies: 10
    Last Post: 2005-12-02, 14:00
  3. 6600 gprs 发送大量rtp延时问题
    By dicson_hu in forum Symbian
    Replies: 9
    Last Post: 2005-11-04, 02:12
  4. Nokia 6600 Socket Server send delay Problem
    By dicson_hu in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2005-10-31, 07:37
  5. Replies: 2
    Last Post: 2004-09-15, 22:47

Posting Permissions

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