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


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 ¸¦ Á¤»èÀûÀ¸·Î È£ÃâÇϼ̽À´Ï´Ù!
");
?>
          
ÃßõÃßõ : 243 Ãßõ ¸ñ·Ï
¹øÈ£ Á¦¸ñ
1,346
À©µµ¿ì ¼­¹ö 2019 Ãë¾àÁ¡ Á¡°Ë º¸¾È
1,345
À©µµ¿ì ¼­¹ö 2019 Ãë¾àÁ¡ Á¡°Ë º¸¾È (windows server 2019)
1,344
Windows Ãë¾àÁ¡Áø´Ü º¸¾È°¡À̵å¶óÀÎ
1,343
Windows Admin Center¸¦ ÅëÇÑ ¼­¹ö °ü¸®
1,342
À©µµ¿ì ¼­¹ö¿¡¼­ ½ÇÇàµÇ´Â ¼­ºñ½º È®ÀÎ
1,341
Chrome NET::ERR CERT REVOKED ÇØ°á¹æ¹ý
1,340
cmd ¸í·É¾î (¸í·É ÇÁ·ÒÇÁÆ® ¸í·É¾î) ¸ðÀ½
1,339
Windows10 ƯÁ¤ ÇÁ·Î±×·¥(OCS 2007 R2)¿¡¼­ ÷ºÎÆÄÀÏ µå·¡±×¾Øµå·ÓÀÌ ¾È µÇ´Â Çö»ó
1,338
À©µµ¿ì ·Î±×, °ü¸® À̺¥Æ® »èÁ¦
1,337
Ŭ¸° ºÎÆÃ
1,336
Windows ±¸¼º ¿ä¼Ò ÀúÀå¼Ò¿¡¼­ ÆÄÀÏ ¼Õ»ó °Ë»ç
1,335
Windows Defender °Ë»ç ±â·Ï »èÁ¦Çϱâ
1,334
°£´ÜÇÑ À©µµ¿ì 10 Á¤Ç° ÀÎÁõ (Å©·¢ÇÁ·Î±×·¥ ÇÊ¿ä¾øÀ½)
1,333
¿À·ù³­ Æú´õ °­Á¦»èÁ¦ ¹æ¹ý
1,332
Å©·Ò¿¡¼­ Ç÷¡½Ã Ç×»ó Çã¿ëÇϵµ·Ï ¼³Á¤Çϱâ (·¹Áö½ºÆ®¸®) reg ÆÄÀÏ ¸¸µé±â
1,331
GPT µð½ºÅ©¸¦ MBR µð½ºÅ©·Î º¯È¯
1,330
MBR µð½ºÅ©¸¦ GPT µð½ºÅ©·Î º¯È¯
1,329
±¸±Û °Ë»öÀ» 200% È°¿ëÇÏ°Ô ÇØÁÖ´Â °Ë»ö ¸í·É¾î ÃÑÁ¤¸®
1,328
[Jquery] jQuery·Î ¿ìŬ¸¯ ¹æÁö, µå·¡±× ¹æÁö, ¼±Åà ¹æÁö (IE10, ÆÄÀ̾îÆø½º, Å©·Ò È®ÀÎ)
1,327
php »ç¿ëÀÚ Á¢¼ÓIP, ºê¶ó¿ìÀúÁ¤º¸, osÁ¤º¸, http, https Á¢¼ÓÇÁ·ÎÅäÄÝ ¾Ë¾Æ¿À±â
1,326
[PHP] IE ºê¶ó¿ìÀú Á¢¼Ó °ËÃâÇϱâ
1,325
À©µµ¿ì10 ½Ã½ºÅÛ ¿¹¾à ÆÄƼ¼Ç È®ÀÎ ¹× »èÁ¦
1,324
À©µµ¿ì10 º¹±¸ ÆÄƼ¼Ç »èÁ¦ ¹æ¹ý
1,323
À©µµ¿ì10 ºÎÆÃÁö¿¬ °ËÀºÈ­¸é¿¡¼­ ¸îºÐ°£ ¸Ó¹«´Â Çö»ó ÇØ°á¹æ¹ý
1,322
»ï¼º³ëÆ®ºÏ ¹ÙÀÌ¿À½º ÁøÀÔÀÌ ºÒ°¡´ÉÇÑ °æ¿ì ¹ÙÀÌ¿À½º À缳ġ¿Í NVRAM ÃʱâÈ­
1,321
ÀͽºÇ÷η¯(IE)ÀÇ ±¸±Û °Ë»ö°ø±ÞÀÚ Çѱ۷Πº¯°æ ¹æ¹ý
1,320
À©µµ¿ì 10 ±âº» ¾Û »èÁ¦ ¹× º¹±¸
1,319
meta ÅÂ±× http-equiv ¼³Á¤¹æ¹ý°ú Â÷ÀÌÁ¡
1,318
±¸±Û(Google)°Ë»ö¿¡¼­ °í±Þ¿¬»êÀÚ¸¦ ÀÌ¿ëÇÏ¿© ¸¹Àº Á¤º¸¸¦ ¾ò´Â ¹æ¹ý
1,317
ÇÁ·Î±×·¥ ¾øÀÌ Çϵåµð½ºÅ© º¹»ç ¹× ¹é¾÷Çϱâ
¸ñ·Ï
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½Ã ºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æħ
Copyright ¨Ï musictrot All rights reserved.