这是我正在使用的代码,(主要来自其他在线资源,顺便提一下):
string uri = "http://www.blah.com";
// Create my request
HttpWebRequest hwrOrdersIDCallback = (HttpWebRequest)WebRequest.Create(uri);
hwrOrdersIDCallback.KeepAlive = false;
hwrOrdersIDCallback.ProtocolVersion = HttpVersion.Version10;
hwrOrdersIDCallback.Method = "POST";
// Turn the req string into a byte stream
byte[] postBytes = Encoding.ASCII.GetBytes(sbOrderIDsLine.ToString());
// Set content type and stream length
hwrOrdersIDCallback.ContentType = "application/x-www-form-urlencoded";
hwrOrdersIDCallback.ContentLength = postBytes.Length;
Stream requestStream = hwrOrdersIDCallback.GetRequestStream();
// Send the POST
requestStream.Write(postBytes, 0, postBytes.Length);
requestStream.Close();
// Grab the response and display it in a label
HttpWebResponse hwrOrdersIDResponse = (HttpWebResponse)hwrOrdersIDCallback.GetResponse();
label1.Text = (new StreamReader(hwrOrdersIDResponse.GetResponseStream()).ReadToEnd());
如果POST成功完成,我应该从服务器获取一些特定数据。我没有得到那些数据,我想知道是否有办法看到这个POST发送到服务器的信息。
答案 0 :(得分:5)
答案 1 :(得分:1)
Fiddler2是调试ajax / service调用流量的绝佳工具。它监控流量,您可以查看呼叫的详细信息,并查看发布和返回的数据。
答案 2 :(得分:0)
使用fiddler。
答案 3 :(得分:0)
在应用程序目录中创建名为< your exe> .config的文件并将其放在其中:
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="System.Net">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
<source name="System.Net.Sockets">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add name="System.Net"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="System.Net.trace.log"/>
</sharedListeners>
<switches>
<add name="System.Net" value="Verbose" />
<add name="System.Net.Sockets" value="Verbose" />
</switches>
</system.diagnostics>
</configuration>
或使用其他人建议的WireShark。跟踪技术更容易设置,但更难阅读。