如何使用webRequest仅获取页面内容?
嗨
在我的代码中,我将带有queryString参数的请求发送到我的网站,并毫无问题地得到结果.
in my code, i send a request to my webSite with queryString parameter(s) and get result without problem.
这是我的代码:
string strUrl = string.Format("http://myWebsite.com/Pages/CustomFormRaw.aspx?moduleGUID=df68c2b1-423d-4842-91c9-68c1c6233e11&insuranceID={0}", insuranceID);
WebClient client = new WebClient();
string downloadString = client.DownloadString(strUrl);
但是结果是我自己的结果(在我的示例0中)和页面内容的组合,就像这样:
but the result is composite of my own result (in my example 0) and page content, something like this :
0
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><link rel="stylesheet" type="text/css" href="/DXR.axd?r=1_20-38coe" /><title>
</title><link href="../Modules/DrugStoreUpdater/Module.css" type="text/css" rel="stylesheet" /></head>
<body>
<form method="post" action="./CustomFormRaw.aspx?moduleGUID=df68c2b1-423d-4842-91c9-68c1c6233e11&insuranceID=1" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJODAyMzMxNDIxZGTJJx/x0n10RtBsW7+0dMqox9AimXUgVTmIzEZumJkYGQ==" />
</div>
....
....
我只想得到0而没有其他页面内容.有人可以帮助我吗?
i want just get 0 without other page content. can anybody help me ?
预先感谢
http://www.codeproject.com/KB/codegen/DatabaseHelper.aspx
http://www.codeproject.com/KB/codegen/DatabaseHelper.aspx
嗨Hamed_1983,
Hi Hamed_1983,
谢谢您在这里发布.
对于您的问题,我建议使用正则表达式来在输出之前获取0,而不包含页面内容.
For your question, I suggest to use regex expression to get the 0 without page content before output.
请尝试以下代码.
string str = "0< !DOCTYPE html >< html xmlns ";//str is the value of downloadstring.
Regex rx = new Regex(@"^\d+");
string a = rx.Match(str).ToString();// a is the 0 which you want to get without page content.
请尝试一下.我希望这会有所帮助.
Please have a try. I hope this would be helpful.
最好的问候,
温迪