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

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 ¸¦ Á¤»èÀûÀ¸·Î È£ÃâÇϼ̽À´Ï´Ù!
");
?>
          
ÃßõÃßõ : 233 Ãßõ ¸ñ·Ï
¹øÈ£ Á¦¸ñ
1,226
android | ²¨Áø È­¸é¿¡¼­ ¾Û ½ÇÇàÇϱâ / Àáµç È­¸é ±ú¿ì±â / Àá±Ý È­¸é À§·Î ½ÇÇà/
1,225
android ÇöÀç WebView¿¡¼­ ¿ÜºÎ ÆäÀÌÁö ºÒ·¯¿À±â / WebView »õâ ¶ç¿ìÁö ¾Ê±â / WebViewClient
1,224
Activity ¸¦ dialog style·Î ¸¸µé±â
1,223
webview ¾Æ·¡ button ³Ö±â
1,222
webview scroll ±â´É ¸·±â(touch´Â µÊ)
1,221
Service µî·ÏÇϱâ
1,220
booting ÈÄ¿¡ ÀÚµ¿À¸·Î ½ÇÇà µÇ´Â app ¸¸µé±â
1,219
[Android] Intent È°¿ë ¿¹½Ã
1,218
Android ¼³Ä¡µÈ ¾îÇà ¸ñ·Ï PackageInfo¸¦ ÅëÇØ °¡Á®¿À±â ¹× ´Ù¸¥ ¾îÇà ½ÇÇà
1,217
[ANDROID(¾Èµå·ÎÀ̵å) ¾Û °³¹ß ±âÃÊ] MEDIAPLAYER À½¾Ç Àç»ýÇϱâ
1,216
[¾Èµå·ÎÀ̵å] ¿ÜºÎ ¾Û ½ÇÇà
1,215
¾Èµå·ÎÀÌµå ¼º´ÉÀ» À§ÇÑ ¼³°è
1,214
ÆÄÀÏ ¾÷·Îµå ¹× ÆĶó¸ÞÅÍ Àü¼Û (sending file & parameters by MultipartEntity / post)
1,213
MediaPlayer °¡·ÎÀÏ ¶§ UI ¼û±â°í Ç®½ºÅ©¸° ¸¸µé±â
1,212
À¥ºä¿¡¼­ html ÅÂ±× ¾ø¾Ö´Â ¹ý(Remove the html tag on loading web page in WebView)
1,211
´Ù¸¥ ¾Û ½ÇÇàÇϰųª Ç÷¹ÀÌ ½ºÅä¾î·Î À̵¿(Launch another app by code)
1,210
À¥ ºä¿¡¼­ ÅÂ±× Á¤º¸ ÃàÃâÇϱâ(Get the information of html tag in WebView of android)
1,209
ÀÚµ¿À¸·Î ¿¡µðÆ®ºä¿¡ Æ÷Ä¿½º µÇ´Â °Í ¸·±â
1,208
addJavascriptInterface ¿À·ù(Android WebView.addJavascriptInterface not Working)
1,207
Ä¿½ºÅÒ Å佺Ʈ ¶ç¿ì±â(To show Custom Toast)
1,206
À¥¿¡¼­ ÆÄÀÏ »çÀÌÁî¿Í ÄÜÅÙÆ®(ÄÁÅÙÃ÷) ŸÀÔ ¾Ë¾Æº¸´Â »ùÇÃÄÚµå
1,205
¾Èµå·ÎÀ̵å ÅؽºÆ® ºä¿¡¼­ Áö¿øÇÏ´Â HTML ű׵é
1,204
ÀÎÅÍ³Ý ÁÖ¼Ò À¯È¿¼º °Ë»ç (regular expression for url)
1,203
SpannableStringÀ¸·Î ÅؽºÆ® ºä¿¡ ¾ÆÀÌÄÜ ³Ö´Â ¹ý
1,202
½ÇÇà°¡´ÉÇÑ ¾Û ¸ñ·Ï (Get launchable apps in android)
1,201
HTMLÀ» ¾Èµå·ÎÀ̵å À¥ºä¿¡ ¸ðµÎ º¸ÀÌ°Ô Çϱâ Using WebView ViewPort in android
1,200
so ÆÄÀÏ ¾Èµå·ÎÀÌµå ½ºÆ©µð¿À¿¡¼­ »ç¿ëÇÏ´Â ¹ý
1,199
[¾Èµå·ÎÀ̵å] È­¸é »çÀÌÁî ±¸Çϱâ
1,198
[¾Èµå·ÎÀ̵å] ¾Èµå·ÎÀÌµå ½ºÆ©µð¿À¿¡¼­ ºôµå ÆÄÀÏ À̸§ ¼öÁ¤Çϱâ.
1,197
¿ÜºÎ ¾Û ½ÇÇà½ÃÅ°±â (launch external app in android)
¸ñ·Ï
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½Ã ºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æħ
Copyright ¨Ï musictrot All rights reserved.