2012-04-25 13 views
0

응용 프로그램의 텍스트 정보를 웹 페이지로 전송하기 위해 WinForms 응용 프로그램을 프로그래밍하려고합니다. 나는 4 개의 텍스트 박스의 텍스트를 포착하여 웹 페이지의 4 개의 텍스트 상자에 붙여 넣을 수있는 방법이 있는지 알고 싶습니다.여러 개의 텍스트 상자에 클립 보드 출력

그들은 동일한 정렬/정렬을 갖습니다. 그 이유는 내 데이터가 SQL 데이터베이스를 통해 관리되고 있으며 텍스트 상자에 관련 정보가 표시되며 복사, 붙여 넣기, 반복보다는 데이터를 전송하는 더 좋은 방법이 필요합니다.

답변

2

당신은 HttpWebRequest을 활용, 각 텍스트 상자에 대한 string을 설정할 수 있습니다

var response = SendNamedStrings("http://example.com", new Dictionary<string,string>{ 
    { "textBox1", textBox1.Text }, 
    { "textBox2", textBox2.Text }, 
    { "textBox3", textBox3.Text }, 
    { "textBox4", textBox4.Text } 
}); 

SendNamedStrings이 될 수있는 곳이 질문에 전에 여러 가지 방법으로 요청을받은 것을

static WebResponse SendNamedStrings(string url, Dictionary<string, string> namedStrings) 
{ 
    string postData = "?" + string.Join("&", namedStrings.Select(pair => string.Format("{0}={1}", pair.Key, pair.Value))); 

    WebRequest request = WebRequest.Create(url); 
    request.Method = "POST"; 
    byte[] byteArray = Encoding.UTF8.GetBytes(postData); 

    request.ContentType = "application/x-www-form-urlencoded"; 
    request.ContentLength = byteArray.Length; 
    Stream dataStream = request.GetRequestStream(); 
    dataStream.Write(byteArray, 0, byteArray.Length); 
    dataStream.Close(); 

    return request.GetResponse(); 
} 

주 같은 스택 오버플로 (여기는 몇 가지 예입니다) :

sending data using HttpWebRequest with a login page

How to add parameters into a WebRequest?

Sending POST data with C#