大家可以参考直接带参数的问题是这样解决的 /** // Create a new WebClient instance.other solve method WebClient myWebClient = new WebClient(); string remoteUri="http://www.action.net?para=test"; // Download home page data. Console.WriteLine("Downloading " + remoteUri); // Download the Web resource and save it into a data buffer. byte[] myDataBuffer = myWebClient.DownloadData (remoteUri); // Display the downloaded data. string download = Encoding.Unicode.GetString(myDataBuffer); textBox1.Text=download; **/
you can try these codes: C#: -------------------------------------------------- string a,b; System.Net.WebClient WebClientObj=new System.Net.WebClient();System.Collections.Specialized.NameValueCollection PostVars=new System.Collections.Specialized.NameValueCollection();PostVars.Add("a",a); PostVars.Add("b",b);try { byte[] byRemoteInfo=WebClientObj.UploadValues("action.asp","POST",PostVars); sRemoteInfo=System.Text.Encoding.Default.GetString(byRemoteInfo); } catch { } -------------------------- sRemoteInfo就是你所要的网页源码,不知道我有没有对理解错误。
很多人都帮不了你,说明你没有把问题说清楚,但我猜你需要的是HttpWebRequest/HttpWebResponse class from System.Net namespace, seeRetrieving HTTP content in .NET with WebRequest/WebResponse http://www.west-wind.com/presentations/dotnetWebRequest/dotnetWebRequest.htm
>>>可惜读出中文是乱码?? 乱码occurs when you output them to a browser? modify your web.config:<configuration> <system.web> <globalization requestEncoding="GB2312" responseEncoding="GB2312" culture="zh-CN" fileEncoding="GB2312" /> </system.web> </configuration>
............... byte[] PostData = System.Text.Encoding.Default.GetBytes(content); ............... using (StreamReader sr = new StreamReader(objResponse.GetResponseStream(),System.Text.Encoding.Default)) { result = sr.ReadToEnd(); } or ............... byte[] PostData = System.Text.Encoding.GetEncoding("gb2312").GetBytes(content); ............... using (StreamReader sr = new StreamReader(objResponse.GetResponseStream(),System.Text.Encoding.GetEncoding("gb2312"))) { result = sr.ReadToEnd(); }
引用saucer(思归, MS .NET MVP) : >>>可惜读出中文是乱码?? 乱码occurs when you output them to a browser? modify your web.config:<configuration> <system.web> <globalization requestEncoding="GB2312" responseEncoding="GB2312" culture="zh-CN" fileEncoding="GB2312" /> </system.web> </configuration> -------------------------------------- or 添加 <META http-equiv="Content-Type" content="text/html; charset=gb2312"> 到你的特定网页里试试!
意思是把action.asp经过浏览器显示在客户端中是以hmtl代码形式来实现的。我想使用程序在客户端中把html读出来。。
To: net_lover(孟子E章)
能否给多点提示
再者,<form action="action.asp" type='post'>中好像是method='post'
还有<input type=text value="a">应该是name='a'
你说的没有错。是我写错啦。只是随手把它写上,具体一点好理解而已。
To:engine_(engine)
其实我是直接想用程序把你用手工的查看--》源文件的工作做了而已。
其实你使用应用程序和web方式。如果能实现也可以
假设本页是通过参数temp=.3781549过来。
假设我的参数temp=只能通过上一页过来的,才能正确显示1374346.xml页面对吗?
http://expert.csdn.net/Expert/topic/1374/1374346.xml?temp=.3781549我想大家都可以看到1374346.xml源文件(客户端的html格式)
我只想用程序把他读出来而已。其实是读取文件
alert(document.body.innerHTML);
试试看
网页本身是一个HTML文件。可以使用程序直接读取该X.html文件来得到HTML代码。
但是如果使用动态语言写(Asp,Php,Jsp,.Net)的网页文件文件,如果使用参数可能存在两种方式。
一种是直接把参数传过去。类如直接在地址栏输入
http://expert.csdn.net/Expert/topic/1374/1374346.xml?temp=.8785974
这里的参数应该是temp=.8785974
另一种是通过另一个文件使用Post的方式把参数传过来,才能接收,其他不允许接收参数。
网页才能通过参数显示正确的结果。。
我想通过第三方程序。无论是asp.php,jsp .net c#(最好是使用c#开发)。能把1374346.xml文件的代码读出来。但是参数是如何过去的。我就不大清楚。
因为浏览网页显示在客户端必须是HTML或者是Xml格式的。我如何把该文件读出来
楼主我说的对吗?
好说好说!
try:
StreamReader sr = new StreamReader("b.html",true,Encoding.GetEncoding("gb2312"));
ArrayList lines = new ArrayList();
while(sr.Peek() !=-1)
{lines.Add(sr.ReadLine());}
this.htmlcont.Text = (string[])lines.ToArray(Type.GetType("System.String"));//设htmlcont是一个多行textbox
sr.Close();
//是不是这个意思?
有点对啦。我的本意思是这样的。不够是从A页面post参数到B页面。
我要求使用C页面程序直接显示如A页面post参数到B页面后网页B页面的源代码
string tempid=this.Request.Form["temp"].ToString();//得到a.html中<input type=text name=temp value=1234">的值 1234;
就可以用这个值对应如a1234.html或a1234.xml文件,
然后可以用流或是dataset.ReadXml(fs)方式读出内容,再表示出来!?
我都快晕了!
/**
// Create a new WebClient instance.other solve method
WebClient myWebClient = new WebClient();
string remoteUri="http://www.action.net?para=test";
// Download home page data.
Console.WriteLine("Downloading " + remoteUri);
// Download the Web resource and save it into a data buffer.
byte[] myDataBuffer = myWebClient.DownloadData (remoteUri);
// Display the downloaded data.
string download = Encoding.Unicode.GetString(myDataBuffer);
textBox1.Text=download;
**/
C#:
--------------------------------------------------
string a,b;
System.Net.WebClient WebClientObj=new System.Net.WebClient();System.Collections.Specialized.NameValueCollection PostVars=new System.Collections.Specialized.NameValueCollection();PostVars.Add("a",a);
PostVars.Add("b",b);try
{
byte[] byRemoteInfo=WebClientObj.UploadValues("action.asp","POST",PostVars);
sRemoteInfo=System.Text.Encoding.Default.GetString(byRemoteInfo);
}
catch
{
}
--------------------------
sRemoteInfo就是你所要的网页源码,不知道我有没有对理解错误。
class from System.Net namespace, seeRetrieving HTTP content in .NET with WebRequest/WebResponse
http://www.west-wind.com/presentations/dotnetWebRequest/dotnetWebRequest.htm
没错,应该是这样带参数过去,读页面的网页源码,
哎可能该问题不好解释。我可要测试测试。。
网站www.test.com中存在两个页面
Post.htm
代码如下
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head><body><form name="form2" method="post" action="Action.asp">
<input type="text" name="kk">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
'--------------------------------------------------------
Action.asp 代码如下
<html>
<title>test html</title>
<body>
<%
T=Request("kk")
Response.Write T
TT=Request.Form("kk")
if tt<>"" then
Response.Write "测试成功"&tt
end if
%>
</body>
</html>
‘-------------------------------------------------------
我想在本机上写一个程序或者在www.test.com网站上直接写一个程序
例如是showcodehtml.aspx得到如下效果
运行后得(网页源码)
<html>
<title>test html</title>
<body>
test 测试成功test
</body>
</html>
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create("http://www.test.com/action.asp");
objRequest.Method = "POST";
objRequest.ContentType = "application/x-www-form-urlencoded";byte[] PostData = System.Text.Encoding.ASCII.GetBytes(content);
objRequest.ContentLength = PostData.Length;
Stream tempStream = objRequest.GetRequestStream();// write the data to be posted to the Request Stream
tempStream.Write(PostData,0,PostData.Length);
tempStream.Close();string result;
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()) )
{
result = sr.ReadToEnd();
}
return result;
使用你的方法测试,的确成功。可是发生该问题。
文件读了一半。后半部分读不出来。我怀疑是
byte[] byRemoteInfo=WebClientObj.UploadValues("action.asp","POST",PostVars);
byte 数组的原因
后面思归的方法,我的好好看看,看能否解决该问题
如果使用WebRequest和WebResponse,到底有没有限制呢??
一、 如果使用engine_(engine)的webclient方法。对参数引用比较好。
(我发现一个Bug,不知道是否是我的错误。如果存在两个一样的参数引用的时候,出现读页面出现中断。
二、如果使用 saucer提供的WebRequest和WebResponse方法。
可以解决上面发现的问题。从该问题解决中发觉另一个问题。。是关于中文的问题的
我使用StreamReader来读,可惜读出中文是乱码,该怎么解决
Encoding enc = Encoding.GetEncoding("gb2312");
StreamReader loResponseStream =new StreamReader(loWebResponse.GetResponseStream(),enc);
乱码occurs when you output them to a browser? modify your web.config:<configuration>
<system.web>
<globalization requestEncoding="GB2312" responseEncoding="GB2312" culture="zh-CN" fileEncoding="GB2312" />
</system.web>
</configuration>
不关web.config的问题
objRequest.ContentType = "application/x-www-form-urlencoded";
byte[] PostData = System.Text.Encoding.ASCII.GetBytes(content);
把第一行去掉,读的内容为空。
如果把第二行改为
byte[] PostData = System.Text.Default.GetBytes(content);
byte[] PostData = System.Text.UTF8.GetBytes(content);
读出来还是乱码
.............
.cur {font-family: ??; font-size: 9pt; color: #ff0000}
.chn {font-family: ??; font-size: 9pt}
.dir {font-family: ??; font-size: 11pt; font-weight: bold}
.sub {font-family: ??; font-size: 9pt}
.hdr {font-family: ??; font-size: 11pt; font-weight: bold}
.itm {FONT-FAMILY: ??; FONT-SIZE: 9pt; LINE-HEIGHT: 14pt}
...............
具体见上面小段代码
如果使用
byte[] PostData = System.Text.Encoding.Unicode.GetBytes(content);
显示为空。到底那里出问题,是否因为servlet解释中文问题
我使用流读]
Encoding enc = Encoding.GetEncoding("gb2312");
StreamReader loResponseStream =new StreamReader(loWebResponse.GetResponseStream(),enc);
已经把编码转换啦。怎么回事。大家帮忙看看
byte[] PostData = System.Text.Encoding.Default.GetBytes(content);
...............
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream(),System.Text.Encoding.Default))
{
result = sr.ReadToEnd();
}
or
...............
byte[] PostData = System.Text.Encoding.GetEncoding("gb2312").GetBytes(content);
...............
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream(),System.Text.Encoding.GetEncoding("gb2312")))
{
result = sr.ReadToEnd();
}
感谢你。可是问题依然没有解决。
我使用你的代码替换我的代码测试一样是中文乱码。
我查正一下。原来我的代码和你的代码根本上没多大的区别。
注意一点是,我的代码读一些网站没问中文乱码问题。只是读特定的不行。该怎么解决。那里出问题?????????????
这是解释 URL 字符 encoding 问题。如果通过 get/post 方式从 browser 返回的参数值中包含汉字信息, servlet 将无法得到正确的值。SUN的 J2SDK 中,HttpUtils.parseName 在解析参数时根本没有考虑 browser 的语言设置,而是将得到的值按 byte 方式解析。这是网上讨论得最多的 encoding 问题。因为这是设计缺陷,只能以 bin 方式重新解析得到的字符串;或者以 hack HttpUtils 类的方式解决。
>>>可惜读出中文是乱码??
乱码occurs when you output them to a browser? modify your web.config:<configuration>
<system.web>
<globalization requestEncoding="GB2312" responseEncoding="GB2312" culture="zh-CN" fileEncoding="GB2312" />
</system.web>
</configuration>
--------------------------------------
or
添加
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
到你的特定网页里试试!
http://expert.csdn.net/Expert/topic/1317/1317542.xml?temp=.3118708
To:engine_(engine)
特定网页的Html代码如下
<HTML>
<head><meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
这里是没有错误。我现在怀疑是否是servlet中读byte的时候读不准确。
如果读进来没有错误。我是否可以考虑把字符再一次转码重新得到正确代码
经过查看你的贴子。你的编码问题跟我的有区别。
我测试过程序读取html,asp, aspx,php都没有该问题产生
如果是读取动态servlet网页看到中文就变成????????
这问题该如何解决。。
http://adionline.myrice.com/Jsp001_offline/jsp001_com/190.html
http://www.chinaunix.net/bbsjh/14/527.html
java的servlet对中文支持问题,我知道怎么解决。
直接用浏览器看是正确的。右键查看源代码是正确的中文符号。
我使用c#的流来读html代码,中文就变成????????
因为在编码方面出了问题。先结帖子.