ehdgks0627 / crazy_layer

what do you want?
GNU General Public License v3.0
0 stars 0 forks source link

API테스트 #1

Closed rlfdldjaak22 closed 8 years ago

rlfdldjaak22 commented 8 years ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.IO;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private string Post_query(params string[] postDatas) // n 은 인자 개수의 양. // 첫 인자는 무조건 URL주소
        {
            HttpWebRequest wReq;
            HttpWebResponse wRes;
            var resResult = "";
            var uri = new Uri(postDatas[0]); // string 을 Uri 로 형변환

            wReq = (HttpWebRequest)WebRequest.Create(uri); // WebRequest 객체 형성 및 HttpWebRequest 로 형변환
            wReq.Method = "POST"; // 전송 방법 "GET" or "POST"
            wReq.ServicePoint.Expect100Continue = false;
            wReq.ContentType = "application/x-www-form-urlencoded";
            String postData = "";
            for (int i = 1; i < postDatas.Length; i++)
            {
                if (i != 1)
                    postData += "&";
                postData += postDatas[i];
            }
            byte[] byteArray = Encoding.UTF8.GetBytes(postData);

            Stream dataStream = wReq.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();
            using (wRes = (HttpWebResponse)wReq.GetResponse())
            {
                Stream respPostStream = wRes.GetResponseStream();
                StreamReader readerPost = new StreamReader(respPostStream, Encoding.GetEncoding("UTF-8"), true);
                resResult = readerPost.ReadToEnd();
            }
            return resResult;
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e) // Register Check
        {
            MessageBox.Show(Post_query("http://layer7.kr/register.php", "id=99qq", "pwd=15qq2", "nickname=동한짱"));
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (Post_query("http://layer7.kr/login.php", "id=99qq", "pwd=15qq2").Equals("0@"))
                MessageBox.Show("실패!");
            else
            {
                MessageBox.Show("성공!");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string i = "";
            string p = "";
            string b = "";
            MessageBox.Show(Post_query("http://layer7.kr/room.php", "type=list"));
            MessageBox.Show(i=Post_query("http://layer7.kr/room.php", "type=create", "max=8", "owner_key=1"));
            MessageBox.Show(Post_query("http://layer7.kr/room.php", "type=list"));
            MessageBox.Show(Post_query("http://layer7.kr/room.php", "type=join", "key=1", "id="+i[0], "nickname=동한짱"));
            MessageBox.Show(Post_query("http://layer7.kr/room.php", "type=user_list", "id="+i[0]));
            MessageBox.Show(Post_query("http://layer7.kr/character.php", "type=create", "key=1", "id="+i[0], "x=1","y=1", "power=1"));
            MessageBox.Show(Post_query("http://layer7.kr/character.php", "type=list", "id="+i[0]));
            MessageBox.Show(Post_query("http://layer7.kr/character.php", "type=update", "key=1", "id="+i[0], "x=0", "y=0", "power=1", "vehicle=0","bubbled=0","lived=1"));
            MessageBox.Show(p=Post_query("http://layer7.kr/item.php", "type=create", "id="+i[0], "x=2", "y=2", "itype=2"));
            MessageBox.Show(Post_query("http://layer7.kr/item.php", "type=list", "id=" + i[0]));
            MessageBox.Show(Post_query("http://layer7.kr/item.php", "type=update", "ate=0", "pr_key=" + p[0]));
            MessageBox.Show(b=Post_query("http://layer7.kr/bubble.php", "type=create", "id=" + i[0], "x=9", "y=9"));
            MessageBox.Show(Post_query("http://layer7.kr/bubble.php", "type=list", "id=" + i[0]));
            MessageBox.Show(Post_query("http://layer7.kr/bubble.php", "type=update", "lived=0", "bu_key=" + b[0]));
            MessageBox.Show(Post_query("http://layer7.kr/room.php", "type=leave", "id=" + i[0], "key=1", "nickname=동한짱"));
            MessageBox.Show(Post_query("http://layer7.kr/room.php", "type=destroy", "id="+i[0]));
        }

    }
}
rlfdldjaak22 commented 8 years ago

API 파싱을 해서 계속 그냥 돌려주시면 됩니다. 걍 돌리기만 하면 됨

rlfdldjaak22 commented 8 years ago

Register Login 의 경우 ID PW 값만 계속 바꾸면 될것.