ȸ¿ø°¡ÀԡžÆÀ̵ð/ºñ¹øã±â
ȨÀ¸·Î


http post [Android]
7³â Àü
´ÙÀ½ ÇÁ·Î±×·¥Àº lesson01.php ¿Í ÀڷḦ ÁÖ°í¹Þ´Â ¿¹Á¦ÀÌ´Ù.
½ÇÇà °á°ú : ÆäÀÌÁö1·Î Àü¼ÛÇÏ°í ÆäÀÌÁö2·Î °á°ú ¹ÞÀ½

main.xml  

<?xml version="1.0" encoding="utf-8"?>
<TabHost
     xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@android:id/tabhost"  
      android:layout_width="fill_parent"  
      android:layout_height="fill_parent">

      <LinearLayout  
            android:layout_width="fill_parent"  
            android:layout_height="fill_parent"  
            android:orientation="vertical">  

           <TabWidget  
                 android:id="@android:id/tabs"  
                 android:layout_width="fill_parent"  
                 android:layout_height="wrap_content"/>

           <TextView
                 android:layout_width="wrap_content"  
                 android:layout_height="wrap_content"/>
           <FrameLayout  
                 android:id="@android:id/tabcontent"  
                 android:layout_width="fill_parent"  
                 android:layout_height="fill_parent">

            <TableLayout  
                  android:id="@+id/page01"  
                  android:layout_width="fill_parent"  
                  android:layout_height="wrap_content"  
                  android:stretchColumns="1">

             <TableRow>
                   <TextView  
                         android:layout_width="wrap_content"  
                         android:layout_height="wrap_content"
                         android:text="ID :"/>
                   <EditText  
                          android:id="@+id/edit_Id"  
                          android:layout_width="fill_parent"  
                          android:layout_height="wrap_content"/>
             </TableRow>
             <TableRow>
                   <TextView  
                         android:layout_width="wrap_content"  
                         android:layout_height="wrap_content"  
                         android:text="PWord : "/>
                    <EditText  
                          android:id="@+id/edit_pword"  
                          android:layout_width="fill_parent"  
                          android:layout_height="wrap_content"  
                          android:password="true"/>
             </TableRow>
             <TableRow>
                   <TextView  
                         android:layout_width="wrap_content"  
                         android:layout_height="wrap_content"  
                         android:text="°³³ä : "/>
                    <EditText  
                          android:id="@+id/edit_title"  
                          android:layout_width="fill_parent"  
                          android:layout_height="wrap_content"/>
             </TableRow>
             <TableRow>
                   <TextView  
                         android:layout_width="wrap_content"  
                         android:layout_height="wrap_content"  
                         android:text="´ëÃ¥ : "/>
                    <EditText  
                          android:id="@+id/edit_subject"  
                          android:layout_width="fill_parent"  
                          android:layout_height="wrap_content"  
                          android:lines="4"/>
             </TableRow>
             <View  
                   android:layout_height="2dip"  
                   android:background="#AAAAAA"/>
             <TableRow>
                   <Button  
                         android:text="   Àü    ¼Û    "  
                         android:id="@+id/button_submit"  
                         android:layout_column="1"
                         android:layout_width="wrap_content"  
                         android:layout_height="wrap_content"/>
             </TableRow>
       </TableLayout>

  <LinearLayout  
        android:id="@+id/page02"  
        android:layout_width="fill_parent"  
        android:layout_height="wrap_content">
        <TextView  
              android:id="@+id/text_result"  
              android:layout_width="fill_parent"  
              android:layout_height="wrap_content"/>
       </LinearLayout>
   </FrameLayout>  
</LinearLayout>
</TabHost>  
          


Manifest.xml¿¡ ´ÙÀ½°ú °°Àº Æ۹̼ÇÀ» Áà¾ß ÇÑ´Ù.

<uses-permission android:name="android.permission.INTERNET"></uses-permission>


project  
  
package com.http_post;

import java.io.*;
import java.net.*;

import android.app.*;
import android.os.*;
import android.util.*;
import android.view.*;
import android.widget.*;

public class MainActivity extends TabActivity {
    // Àü¿ªº¯¼ö¸¦ ¼±¾ðÇÑ´Ù
    TabHost mTabHost = null;
    String myId, myPWord, myTitle, mySubject, myResult;
  
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        mTabHost = getTabHost();          // Tab ¸¸µé±â
        mTabHost.addTab(mTabHost.newTabSpec("tab_1").setIndicator("¼­¹ö·Î Àü¼Û").setContent(R.id.page01));
        mTabHost.addTab(mTabHost.newTabSpec("tab_2").setIndicator("¼­¹ö¿¡¼­ ¹ÞÀ½").setContent(R.id.page02));
        findViewById(R.id.button_submit).setOnClickListener(buttonClick);  
    }
    
    //------------------------------
    //    button Click
    //------------------------------
    Button.OnClickListener buttonClick = new Button.OnClickListener() {
        public void onClick(View v) {
           // »ç¿ëÀÚ°¡ ÀÔ·ÂÇÑ ³»¿ëÀ» Àü¿ªº¯¼ö¿¡ ÀúÀåÇÑ´Ù
           myId = ((EditText)(findViewById(R.id.edit_Id))).getText().toString();  
           myPWord = ((EditText)(findViewById(R.id.edit_pword))).getText().toString();  
           myTitle = ((EditText)(findViewById(R.id.edit_title))).getText().toString();  
           mySubject = ((EditText)(findViewById(R.id.edit_subject))).getText().toString();  
    
           HttpPostData();   // ¼­¹ö¿Í ÀÚ·á ÁÖ°í¹Þ±â
       }
    };  
    
    //------------------------------
    //   Http Post·Î ÁÖ°í ¹Þ±â
    //------------------------------
    public void HttpPostData() {
         try {
              //--------------------------
              //   URL ¼³Á¤ÇÏ°í Á¢¼ÓÇϱâ
              //--------------------------
              URL url = new URL("lesson01.php");       // URL ¼³Á¤
              HttpURLConnection http = (HttpURLConnection) url.openConnection();   // Á¢¼Ó
              //--------------------------
              //   Àü¼Û ¸ðµå ¼³Á¤ - ±âº»ÀûÀÎ ¼³Á¤ÀÌ´Ù
              //--------------------------
              http.setDefaultUseCaches(false);                                            
              http.setDoInput(true);                         // ¼­¹ö¿¡¼­ Àб⠸ðµå ÁöÁ¤
              http.setDoOutput(true);                       // ¼­¹ö·Î ¾²±â ¸ðµå ÁöÁ¤  
              http.setRequestMethod("POST");         // Àü¼Û ¹æ½ÄÀº POST

              // ¼­¹ö¿¡°Ô À¥¿¡¼­ <Form>À¸·Î °ªÀÌ ³Ñ¾î¿Â °Í°ú °°Àº ¹æ½ÄÀ¸·Î ó¸®Ç϶ó´Â °É ¾Ë·ÁÁØ´Ù
              http.setRequestProperty("content-type", "application/x-www-form-urlencoded");
              //--------------------------
              //   ¼­¹ö·Î °ª Àü¼Û
              //--------------------------
              StringBuffer buffer = new StringBuffer();
              buffer.append("id").append("=").append(myId).append("&");                 // php º¯¼ö¿¡ °ª ´ëÀÔ
              buffer.append("pword").append("=").append(myPWord).append("&");   // php º¯¼ö ¾Õ¿¡ '$' ºÙÀÌÁö ¾Ê´Â´Ù
              buffer.append("title").append("=").append(myTitle).append("&");           // º¯¼ö ±¸ºÐÀº '&' »ç¿ë  
              buffer.append("subject").append("=").append(mySubject);
            
              OutputStreamWriter outStream = new OutputStreamWriter(http.getOutputStream(), "EUC-KR");
              PrintWriter writer = new PrintWriter(outStream);
              writer.write(buffer.toString());
              writer.flush();
              //--------------------------
              //   ¼­¹ö¿¡¼­ Àü¼Û¹Þ±â
              //--------------------------
              InputStreamReader tmp = new InputStreamReader(http.getInputStream(), "EUC-KR");  
              BufferedReader reader = new BufferedReader(tmp);
              StringBuilder builder = new StringBuilder();
              String str;
              while ((str = reader.readLine()) != null) {       // ¼­¹ö¿¡¼­ ¶óÀδÜÀ§·Î º¸³»ÁÙ °ÍÀ̹ǷΠ¶óÀδÜÀ§·Î Àд´Ù
                   builder.append(str + "\n");                     // View¿¡ Ç¥½ÃÇϱâ À§ÇØ ¶óÀÎ ±¸ºÐÀÚ Ãß°¡
              }
              myResult = builder.toString();                       // Àü¼Û°á°ú¸¦ Àü¿ª º¯¼ö¿¡ ÀúÀå
             ((TextView)(findViewById(R.id.text_result))).setText(myResult);
             Toast.makeText(MainActivity.this, "Àü¼Û ÈÄ °á°ú ¹ÞÀ½", 0).show();
         } catch (MalformedURLException e) {
                //
         } catch (IOException e) {
                //  
         } // try
    } // HttpPostData
} // Activity
        


lesson01.php  

<?
// º¯¼ö ³»¿ë È®ÀÎ
if ($id == "") $id = "³Ê´Â IDµµ ¾ø³Ä?";
if ($pword == "") $pword = "ĥĥ¸Â°Ô ºñ¹Ð¹øÈ£µµ Àؾî¸Ô°í ´Ù´Ï³×...";
if ($title == "") $title = "Áõ¸» °³³ä¾ø´Â »ç¶÷Àϼ¼...";
if ($subject == "") $subject = "¿¡±¸~~ ´ëÃ¥ÀÌ ¾ø³×...";
// º¯¼ö ³»¿ë Ãâ·Â
echo ("
  ´Ô²²¼­ PHP·Î Àü¼ÛÇÑ ³»¿ëÀÔ´Ï´Ù
  -----------------------------------------------------------------\r\n
  »ç¿ëÀÚ ID : $id \r\n
  ºñ¹Ð¹øÈ£ : $pword \r\n
  °³³ä : $title \r\n
  ´ëÃ¥ : $subject \r\n
  -----------------------------------------------------------------\r\n
  ÃàÇϵ帳´Ï´Ù. lesson01.php ¸¦ Á¤»èÀûÀ¸·Î È£ÃâÇϼ̽À´Ï´Ù!
");
?>
          
ÃßõÃßõ : 241 Ãßõ ¸ñ·Ï
¹øÈ£ Á¦¸ñ
1,196
Service & Notification(¾Ë¸²¹Ù¶ç¿ì±â) ÀÌ¿ëÇϱâ
1,195
È­¸é ȸÀü(rotation) ó¸®
1,194
[Android] Àüüȭ¸é, title bar ¾ø¾Ö±â, status bar ¾ø¾Ö±â
1,193
ANDROID(¾Èµå·ÎÀ̵å) ¾Û °³¹ß ±âÃÊ] MEDIAPLAYER À½¾Ç Àç»ýÇϱâ
1,192
[Android]MediaPlayer¿¡¼­ »ç¿îµå¸¦ Àç»ýÇÏ´Â µÎ °¡Áö °æ·Î
1,191
¾Èµå·ÎÀ̵å Intent »ç¿ë¹ý
1,190
¾Èµå·ÎÀ̵å È­¸é Á¤¸®
1,189
ffmpeg ¿ÀÇ ¼Ò½º on ¾Èµå·ÎÀ̵å
1,188
WebView¿¡¼­ <a> ű×ÀÇ "_blank" target ó¸®Çϱâ.
1,187
Ư¼ö¹®ÀÚ, Ư¼ö¹®ÀÚÇ¥, Ư¼ö¹®ÀÚ ÇÏÆ®, ¿¹»Û Ư¼ö¹®ÀÚ
1,186
MediaPlayer 5¹ø¸¸ ¹Ýº¹Àç»ý
1,185
ÆÄÀÏ À§Ä¡¿¡ µû¸¥ ¹Ìµð¾î Àç»ý »ùÇÃÄÚµå
1,184
MJPEG on Android anyone?
1,183
Android °³¹ß
1,182
¾Èµå·ÎÀ̵å : ¾×ƼºñƼ ¶óÀÌÇÁ »çÀÌŬ (Activity Life Cycle)
1,181
¾Èµå·ÎÀ̵å ÇÁ·Î±×·¥ ÄÚµå·Î À¥ ºê¶ó¿ìÀú ½ÇÇàÇϱ⠿¹Á¦ (ÀÎÅÙÆ® »ç¿ë)
1,180
Áøµ¿ È¿°ú [Android]
1,179
Á¾·á ´ÙÀ̾ó·Î±× [Android]
1,178
´Ù¸¥¾Û È£Ãâ [Android]
1,177
TabActivity back key Event [Android]
1,176
³×Æ®¿öÅ© »óÅ [Android]
1,175
¾Èµå·ÎÀ̵忡¼­ À¥¼­¹ö¿¡ post·Î ±Û¾²±â [Android]
1,174
Webview ¼Ò½º [Android]
1,173
Coach mark View [Android]
1,172
¸ÖƼ ÇØ»óµµ [Android]
1,171
Webview source [Android]
1,170
°øÀ¯ Intent [Android]
1,169
intent uri ¸ðÀ½ [Android]
http post [Android]
1,167
http ¿äû [Android]
¸ñ·Ï
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½Ã ºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æħ
Copyright ¨Ï musictrot All rights reserved.