How to send a text to the server through post method

Put your problem here if it does not fit any of the other categories.

How to send a text to the server through post method

Postby NithinG » Wed Feb 27, 2008 6:35 am

HI plusminus,

I have to send large text data to the server and through the URL , sending large text data is not possible.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.                 DataOutputStream dos;
  3.  
  4.                 OutputStream os;
  5.  
  6.                 URLConnection con;
  7.  
  8.                 String urlString = "http://192.168.157.35:8080/myown/Login.do";
  9.  
  10.  
  11.  
  12.        String username="Hello World";
  13.  
  14.        URL url;
  15.  
  16.        try {
  17.  
  18.                     url = new URL(urlString);
  19.  
  20.                     con=url.openConnection();
  21.  
  22.                     if (con instanceof HttpURLConnection)
  23.  
  24.                     {
  25.  
  26.                               LOG.error("This is HttpURLConnection");
  27.  
  28.                               ((HttpURLConnection)con).setRequestMethod("POST");
  29.  
  30.                               con.setDoInput(true);
  31.  
  32.                               con.setDoOutput(true);
  33.  
  34.                               os = con.getOutputStream();
  35.  
  36.                                //con.getReadTimeout();
  37.  
  38.                               dos = new DataOutputStream(os);
  39.  
  40.                
  41.  
  42.                               dos.writeUTF(username);
  43.  
  44.                              int check = con.getReadTimeout();
  45.  
  46.                               //dos.close();
  47.  
  48.                               LOG.error("connection successfull"+check);
  49.  
  50.                     }
  51.  
  52.           }
  53.  
  54.       catch (IOException e) {
  55.  
  56.       }
  57.  
  58.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


This is the code which i have tried and its not connecting to the server. Can you send me some sample code. :cry:

Regards,
NithinG :D
NithinG
Developer
Developer
 
Posts: 36
Joined: Wed Feb 27, 2008 6:24 am

Top

Postby plusminus » Wed Feb 27, 2008 10:46 am

Hello NithinG,

why is "sending large text data is not possible" :?:
Please use the search function.
It will find things like: :src: Doing HTTP Post with Android.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

How to add links dynamically in to the activity?

Postby NithinG » Thu Feb 28, 2008 10:20 am

Hi,

i want to create some links dynamically in to the activity. Can you suggest some methods for that.

Regards,
NithinG
NithinG
Developer
Developer
 
Posts: 36
Joined: Wed Feb 27, 2008 6:24 am

Postby plusminus » Thu Feb 28, 2008 12:47 pm

Hello NithinG,

what do you exactly mean with "links" :?:

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Hello PlusMinus,

Postby NithinG » Fri Feb 29, 2008 5:44 am

Actually i need any components like button or TextView or anything like that dynamically i need to create..
i tried a code like this..
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onCreate(Bundle icicle) {
  2.  
  3.         super.onCreate(icicle);
  4.  
  5.        setContentView(R.layout.main);
  6.  
  7.        
  8.  
  9.        
  10.  
  11.         for(int i=0;i<10;i++)
  12.  
  13.         {
  14.  
  15.                 TableLayout tl = (TableLayout)findViewById(R.id.myTableLayout);
  16.  
  17.                 /* Create a new row to be added. */
  18.  
  19.                 TableRow tr = new TableRow(this);
  20.  
  21.                  
  22.  
  23.                      /* Create a Button to be the row-content. */
  24.  
  25.                      Button b = new Button(this);
  26.  
  27.                      b.setText("Dynamic Button");
  28.  
  29.                      
  30.  
  31.                      /* Add Button to row. */
  32.  
  33.                      tr.addView(b);
  34.  
  35.                    /* Add row to TableLayout. */
  36.  
  37.                    tl.addView(tr,new TableLayout.LayoutParams(
  38.  
  39.                      LayoutParams.FILL_PARENT,
  40.  
  41.                      LayoutParams.WRAP_CONTENT));
  42.  
  43.         }
  44.  
  45.     }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


this instead if creating button like this i want to create it inside an onclick event of a button...
So i needed to specify some CONTEXT.... like TextView tv = new TextView(CONTEXT); What i have to give as a context if i am writing that statement inside an OnClick event???
NithinG
Developer
Developer
 
Posts: 36
Joined: Wed Feb 27, 2008 6:24 am

Postby plusminus » Fri Feb 29, 2008 4:01 pm

Hello Nithin,

use the this-pointer of the surrounding Activity,like

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. ...new Button(OuterActivity.this);
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 12 guests