Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 08:42, 25 September 2007.

How to send POST data to a web server

From Forum Nokia Wiki

Using Java ME with MIDP 1.0 or MIDP 2.0 you can send and receive information from/to a webserver using HTTP protocol. If you want to send data using POST method, you should use this code:

First load the required libraries:

import javax.microedition.io.*;
import java.io.*;

Then use this code in a function:

HttpConnection c = (HttpConnection) Connector.open("http://www.domain.com/url");
c.setRequestMethod(HttpConnection.POST);
byte[] data; 
// data should be filled with binary data to send
c.setRequestProperty("Content-Length", Integer.toString(data.length));
 
OutputStream sending = c.openOutputStream();
sending.write(data);
sending.close();

If you want to send POST parameters to be read by PHP, ASP.NET or other server platform, you should make a string parameter like this

// This is a sample
String strData = "name=" + game.getName() + "&score=" + game.getScore();
byte[] data = strData.getBytes();

And also, you have to define an HTTP parameter like this:

c.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
Related Discussions
Thread Thread Starter Forum Replies Last Post
Data Handling kalyanich General Symbian C++ 1 2006-10-04 11:33
HTTP POST Problem with SDK's tonyhabayeb Mobile Java Tools & SDKs 11 2006-08-10 23:14
HTTP POST Problem with SDK's tonyhabayeb Mobile Java Networking & Messaging & Security 1 2006-06-16 13:41
N93 as a BT-Server for NonJava Clients Lichtens Mobile Java Networking & Messaging & Security 3 2007-06-18 09:12
Web forms and browsing mayankkedia General Symbian C++ 2 2006-11-21 16:05
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtopicQUqfnTopicZjavaQ
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX