我为Raspberry Pi(Windows IoT)创建了自己的Web服务器。
我有winform桌面应用程序向我的网络服务器发出请求:
StringBuilder sb = new StringBuilder();
sb.Append("<informedworker>");
sb.Append("<request name='Customer' action='GET' verb='*'>");
sb.Append("</request>");
sb.Append("</informedworker>");
Uri url = new Uri("http://192.168.0.6/DATA_START" + sb.ToString() + "DATA_END");//, query, key));
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
using (var response = request.GetResponse())
using (var stream = response.GetResponseStream())
using (var reader = new StreamReader(stream))
{
HttpStatusCode statusCode = ((HttpWebResponse)response).StatusCode;
string contents = reader.ReadToEnd();
}
在我的网络服务器(UWP)中,我有:
StringBuilder request = new StringBuilder();
using (IInputStream input = args.Socket.InputStream)
{
byte[] data = new byte[BufferSize];
IBuffer buffer = data.AsBuffer();
uint dataRead = BufferSize;
while (dataRead == BufferSize)
{
await input.ReadAsync(buffer, BufferSize, InputStreamOptions.Partial);
request.Append(ASCIIEncoding.ASCII.GetString(data, 0, data.Length));
dataRead = buffer.Length;
}
System.Diagnostics.Debug.WriteLine(request.ToString());
我在这里读到的回复是:
GET /DATA_START%3Cinformedworker%3E%3Crequest%20name='Customer'%20action='GET'%20verb='*'%3E%3C/request%3E%3C/informedworker%3EDATA_END HTTP/1.1
Host: 192.168.0.6
Connection: Keep-Alive
正如您所见,%3E%3C已取代&#39;&lt;&#39;
我当然可以创建自己的解析器来翻译&#39;这些&#39;特别&#39;人物回来了。
这种情况是否有内置编码器?
感谢