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


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,166
Android WebView Facebook Login (popup/redirection issues)
1,165
Loading GIF [Android]listView ¿ø°ÝÀ̹ÌÁö [Android]
1,164
¾Û ¹öÀü üũ ½ºÅä¾î·Î À̵¿ [Android]
1,163
WebViewClient [Android]
1,162
http post get Àü¼Û
1,161
À¥ºä ¸Þ¼Òµå È£ÃâÀÌ ¾ÈµÉ ¶§ (android.permission.INTERACT_ACROSS_USERS_FULL)
1,160
°³¹ß Áß ¿¡·¯ ¹ß»ý½Ã ¿¡·¯ ³»¿ë È®ÀÎ, ÇØ°á¹æ¹ý [Android]
1,159
ij½Ã Áö¿ì±â [Android]
1,158
¹Ù·ÎÇ®¾î(¼öÇÐ ¹®Á¦ ÁúÀÇÀÀ´ä SNS) ¿¡ »ç¿ëµÈ ¿ÀǼҽº ¶óÀ̺귯¸® [Android]
1,157
¿ÀǼҽº ¶óÀ̺귯¸® ¸ðÀ½ [Android]
1,156
´Ü¸»±â ¹öÀü Á¤º¸ [Android]
1,155
Android webview °³¹ß½Ã ¾Ë¾ÆµÖ¾ß ÇÒ °Íµé [Android]
1,154
[¾Èµå·ÎÀ̵å] ¾Û ³»¿¡¼­ ·±Å¸ÀÓ ±ÇÇÑÀ» ¿äûÇÏ´Â ¹æ¹ý
1,153
webview µ¿¿µ»ó Àç»ý [Android]
1,152
android studio DefaultHttpClient, HttpClient import ¿¡·¯
1,151
[Android] ANR À̶õ?
1,150
¾Èµå·ÎÀÌµå ¿ÀǼҽº
1,149
Android] AlarmManager ÀÏÁ¤½Ã°£ À̺¥Æ® ½ÇÇà
1,148
[Android] Webview url ¼û±â±â
1,147
[Android] webview ssl ¹®Á¦
1,146
[Android] Webview 404 ¿¡·¯ ó¸®
1,145
[Android] Webview ¸Þ¼Òµå
1,144
[¾Èµå·ÎÀ̵å] À¥ºä(WebView ¿¡¼­ ÀÚ¹Ù½ºÅ©¸³Æ® alert ¶ç¿ì±â
1,143
(Android) WebView _blank ó¸®
1,142
webvew ¿¡¼­ ºê¶ó¿ìÀú·Î ¸µÅ©(_blank)
1,141
[Android]¾Èµå·ÎÀ̵å Intent »ç¿ë¹ý
1,140
¾Èµå·ÎÀÌµå ¹Ìµð¾î Ç÷¹À̾î (MediaPlayer) ¿¹Á¦
1,139
[Android] BroadcastReceiver »ç¿ëÇϱâ
1,138
Media Player¸¦ ÀÌ¿ëÇÑ À½¾Ç Àç»ý
1,137
[°³¹ß Tip] Activity³» ¹è°æÀ» Åõ¸íÇÏ°Ô Çϱâ
¸ñ·Ï
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½Ã ºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æħ
Copyright ¨Ï musictrot All rights reserved.