我正在處理以下代碼。如何查看在C中發送的請求#
Int32 port = 7101;
IPAddress localAddr1 = IPAddress.Parse("117.239.85.13");
MemoryStream ms = new MemoryStream();
XmlDocument doc = new XmlDocument();
String message_text = "<estel><header><requesttype>CREDIT</requesttype></header><request><agentcode>910000006789</agentcode><vendorcode>HELLOTV</vendorcode><pin>***************</pin><destination>919555518484</destination><agenttransid>*****</agenttransid><amount>10</amount><productcode>SKUA</productcode><clienttype>portal</clienttype><comments>abcd</comments></request></estel>";
doc.LoadXml(message_text);
doc.Save(ms);
ms.Seek(0, SeekOrigin.Begin);
Byte[] data = ms.ToArray();
TcpClient client = new TcpClient();
client.Connect(localAddr1, port);
MessageBox.Show(client.Connected.ToString()); // Connection was established here. Returns TRUE value
NetworkStream stream = client.GetStream();
StreamWriter writer = new StreamWriter(stream, Encoding.UTF8);
writer.AutoFlush = false;
writer.Write(Encoding.UTF8.GetBytes(message_text).Length);
writer.Flush();
stream.Write(data, 0, data.Length);
MessageBox.Show(stream.DataAvailable.ToString()); // Returns TRUE value
Byte[] bytes = new Byte[client.ReceiveBufferSize];
string responseData;
stream.Read(bytes, 0, Convert.ToInt32(client.ReceiveBufferSize));
responseData = Encoding.UTF8.GetString(bytes); // We are getting response here
stream.Close();
client.Close();
textBox1.Text = responseData.ToString();
這裏我使用IP和端口號向Web服務提供商發送XML數據。發送請求後,我收到以下響應15次
<estel><header><responsetype>INVALID REQUEST</responsetype></header></estel>
看起來有些額外的內容正在追加。我如何查看發送的請求,以便我可以更正它?