2014년 1월 6일 월요일

[예제]HTTP - WebClient, OpwnWrite를 이용한 데이터 업로드[재직자무료교육/프로그래머교육/구로디지털IT교육,오라클/자바/닷넷/C#/iOS/안드로이드/아이폰교육]

[예제]HTTP - WebClient, OpwnWrite를 이용한 데이터 업로드[재직자무료교육/프로그래머교육/구로디지털IT교육,오라클/자바/닷넷/C#/iOS/안드로이드/아이폰교육]

//POST 방식으로 데이터를 업로드 하는 예제 입니다.

using System;
using System.Net;
using System.IO;
using System.Text;
using System.Web;

class OpenWrite
{
static void Main()
{
string uriString = "http:/write_ok.php";

string name = "tester";
string email = "oracler@oraclejavanew.kr";
string subject = "방가와요...";
string password = "1111";
string memo = "사이트 오픈을 축하 합니다.";
string id = "guest";

string postData = "id=" + HttpUtility.UrlEncode(id) + "&" +
"name=" + HttpUtility.UrlEncode(name) + "&" +
"email=" + HttpUtility.UrlEncode(email) + "&" +
"subject" + HttpUtility.UrlEncode(subject) + "&" +
"password=" + HttpUtility.UrlEncode(password) + "&" +
"memo" + HttpUtility.UrlEncode(memo);

byte[] postArray = Encoding.Default.GetBytes(postData);

// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
myWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

// postStream implicitly sets HTTP POST as the request method.
Console.WriteLine("Uploading to {0} ...", uriString);
Stream postStream = myWebClient.OpenWrite(uriString);

postStream.Write(postArray,0,postArray.Length);

// Close the stream and release resources.
postStream.Close();

Console.WriteLine("\n 방명록에 성공적으로 글을 올렸습니다...");
}
}
 


  • JAVA
  • ORACLE
  • iPhone/Android
  • .NET
  • 표준웹/HTML5
  • 채용/취업무료교육
  • 초보자(재학생)코스

  • 댓글 없음:

    댓글 쓰기