×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    47

    how to pass parameters into http post method?

    hi,
    i have never used http post method.there is one example code for htttp multipart post.

    but i dont know how to pass parameters to it.

    i want to upload small mp3 file in which i have to pass one file id and second file name.

    so how can i do it ?
    can anyone help me out?

  2. #2
    Regular Contributor
    Join Date
    May 2010
    Posts
    94

    Re: how to pass parameters into http post method?


  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    47

    Re: how to pass parameters into http post method?

    hi nitin
    thankx for replying.

    I have read this tutorial.but see my code below.
    httpcon=(HttpConnection)Connector.open("http://192.168.0.152/google/uploadSong?",Connector.READ_WRITE);
    httpcon.setRequestMethod(HttpConnection.POST);
    httpcon.setRequestProperty("Content-type","application/x-www-form-urlencoded");
    httpcon.setRequestProperty("Content-type","audio/mpeg");
    os=httpcon.openOutputStream();
    os.write(params.getBytes("utf-8"));
    fc=(FileConnection)Connector.open("file:///E/sample.mp3",Connector.READ_WRITE);
    fileis=fc.openInputStream();

    I have to pass two parameters in post method and just trying to write mp3 file.
    can u tell me what is wrong with this code.

    suppose if i use multipart example how can i pass two parameters and write the mp3 file.

    thankx

  4. #4
    Regular Contributor
    Join Date
    May 2010
    Posts
    94

    Re: how to pass parameters into http post method?

    What is your two paramaters.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Posts
    47

    Re: how to pass parameters into http post method?

    i have to pass i) id of file and name of file

    like id_user="1234"
    trackName="sample.mp3"

  6. #6
    Regular Contributor
    Join Date
    May 2010
    Posts
    94

    Re: how to pass parameters into http post method?

    String data = "id_user=1234&trackname=sample.mp3";
    os.write(data.getBytes);
    And then Write the mp3 files.
    os.write(samplemp3.getBytes());

  7. #7
    Registered User
    Join Date
    Nov 2010
    Posts
    47

    Re: how to pass parameters into http post method?

    i am doing the same .
    String userid="id_user=8379";
    String filename="trackName=sample.mp3";
    String params=userid+"&"+filename;
    InputStream fileis;
    try
    {
    httpcon=(HttpConnection)Connector.open("http://192.168.0.152/google/uploadSong?output=json",Connector.READ_WRITE);
    httpcon.setRequestMethod(HttpConnection.POST);
    httpcon.setRequestProperty("Content-type","application/x-www-form-urlencoded");
    httpcon.setRequestProperty("Content-type","audio/mpeg");
    os=httpcon.openOutputStream();
    //params os.write(params.getBytes("utf-8"));
    fc=(FileConnection)Connector.open("file:///E/sample.mp3",Connector.READ_WRITE);
    fileis=fc.openInputStream();
    StringBuffer buffer=new StringBuffer();
    int ch;
    while ((ch=fileis.read())!=-1) {
    buffer.append((char)ch);
    }
    String data=buffer.toString();
    //mp3 file os.write(data.getBytes());
    os.close();

    can you say that is there any error in this code?

  8. #8
    Regular Contributor
    Join Date
    May 2010
    Posts
    94

    Re: how to pass parameters into http post method?

    I think the mp3 File should not read as a String content.

    I have not the actual code but It should be like this.

    byte[] responseData = new byte[10000];
    int length = 0;
    while (-1 != (length = inputStream.read(responseData))) {
    os.write(responseData, 0, length);
    }

Similar Threads

  1. HTTP GET and POST METHOD
    By hornsattack in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2009-08-03, 11:26
  2. Nokia supports HTTP POST Method?
    By ZaidShah in forum General Development Questions
    Replies: 1
    Last Post: 2009-07-22, 07:15
  3. Can we use PUT method instead of Post in HTTP
    By ash_21 in forum Symbian Networking & Messaging (Closed)
    Replies: 3
    Last Post: 2009-07-21, 08:44
  4. http example post method problem
    By nabaparna in forum Symbian Networking & Messaging (Closed)
    Replies: 4
    Last Post: 2007-06-28, 08:58
  5. And HTTP POST method Works !!
    By n_sidhaye in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2003-11-08, 17:54

Posting Permissions

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