tags:

views:

85

answers:

3

lets assume this URL...

http://www.example.com/page.php?id=10            

(Here id is no GET its POST Request...)

now here i wanna send the the id = 10...to the server's page page.php because it is POST method i m not able to send this like /page.php?id=10...

how can i do this in java....

i did this :

URL aaa = new URL("http://www.example.com/page.php");
URLConnection ccc = aaa.openConnection();

now whats next...just show me how to send id = 10 on page.php using Java...aa

A: 

HttpURLConnection.setRequestMethod()

EJP
it it HttpURLConnection.setRequestMethod() :)
StudiousJoseph
+3  A: 
String rawData = "id=10";
String type = "application/x-www-form-urlencoded";
String encodedData = encode( rawData ); 
URL u = new URL("http://www.example.com/page.php");
URLConnection c = u.openConnection();
c.setDoOutput(true);
conn = (HttpURLConnection)c;
conn.setRequestMethod( HttpConnection.POST );
conn.setRequestProperty( "Content-Type", type );
conn.setRequestProperty( "Content-Length", encodedData.length() );
OutputStream os = conn.openOutputStream();
os.write( encodedData.getBytes() );
MrOhad
+3  A: 

Hi,

I recommend to use Apache HttpClient. its faster and easier to implement.

PostMethod post = new PostMethod("http://jakarata.apache.org/");
        NameValuePair[] data = {
          new NameValuePair("user", "joe"),
          new NameValuePair("password", "bloggs")
        };
        post.setRequestBody(data);
        // execute method and handle any error responses.
        ...
        InputStream in = post.getResponseBodyAsStream();
        // handle response.

for more information check this url: http://hc.apache.org/

mohammad shamsi