我想从给定的 URL 获取 http 请求标头和发布数据....怎么做?....我必须显示 http 请求标头、http 响应标头、给定 url 的内容和发布数据...
下面是我的代码......
private void button1_Click(object sender, EventArgs e)
{
try
{
string url = txtUrl.Text;
HttpWebRequest WebRequestObject = (HttpWebRequest)HttpWebRequest.Create(url);
HttpWebResponse Response = (HttpWebResponse)WebRequestObject.GetResponse();
HttpStatusCode code = Response.StatusCode;
txtStatus.Text = code.ToString();
txtResponse.Text = Response.Headers.ToString();
// Open data stream:
Stream WebStream = Response.GetResponseStream();
// Create reader object:
StreamReader Reader = new StreamReader(WebStream);
// Read the entire stream content:
string PageContent = Reader.ReadToEnd();
// Cleanup
Reader.Close();
WebStream.Close();
Response.Close();
txtContent.Text = PageContent;
// var request = WebRequest.Create("http://www.livescore.com ");
//var response = request.GetResponse();
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
但是如何获取我不知道的发布数据和 http 请求标头...请帮助