将文本值从WinCE c#应用程序传递到WebApp

本文关键字:WebApp 应用程序 文本 WinCE | 更新日期: 2023-09-27 18:06:03

我在WinCE上运行RFID手持设备。供应商为我提供了一个简单的应用程序的源代码,该应用程序从扫描的RFID标签中读取RFID代码,并将其显示在应用程序本身(Windows Form)中。我需要这个值到达我的web应用程序,无论是通过POST, GET方法或通过打开新的IE窗口。谢谢你的忠告。

将文本值从WinCE c#应用程序传递到WebApp

您可以创建一个WebRequest对象并将其发布到网页上,这一点都不麻烦:

http://msdn.microsoft.com/en-us/library/debx8sh9.aspx

// Create a request using a URL that can receive a post. 
WebRequest request = WebRequest.Create ("http://www.contoso.com/PostAccepter.aspx ");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "This is a test that posts this string to a Web server.";
byte[] byteArray = Encoding.UTF8.GetBytes (postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream ();
// Write the data to the request stream.
dataStream.Write (byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close ();
// Get the response.
WebResponse response = request.GetResponse ();
// Display the status.
Console.WriteLine (((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd ();
// Display the content.
Console.WriteLine (responseFromServer);
// Clean up the streams.
reader.Close ();
dataStream.Close ();
response.Close ();