0

您能否请教我如何查看我创建的、使用 c# 在 Web 服务器位置编写的字符串。

我在文件中看到的输出,我在服务器位置写入的只有“日期”、“时间”和 4 个逗号后的“我的 IP 地址”

像这样的东西:2013/11/12,00:20:56,,,,,xxxx,

我希望看到我创建的字符串写在我们看到逗号的地方。

这是我的代码:

// Create a request using a URL that can receive a post. 
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(""www.xyz.com/.../....MyUrlLocation");

// Set the Method property of the request to POST.
request.Method = "POST";

// Create POST data and convert it to a byte array.
string postData = Environment.UserName + "," + sw.Elapsed.ToString() + "," + NumberOFProperties.ToString();

ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byteArray = encoding.GetBytes(postData);
//byte[] byteArray = Encoding.UTF8.GetBytes(postData);

// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "PUT";

// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;

// Get the request stream.
Stream dataStream = request.GetRequestStream();
bool bIfCanWrite = dataStream.CanWrite;

// 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();

// 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();
string strLine = reader.ReadLine();

// Display the content.
Console.WriteLine(responseFromServer);

// Clean up the streams.
reader.Close();
dataStream.Close();
response.Close();
4

0 回答 0