江湖救急—关于网络信息的获取?欢迎进贴看看,交个朋友,哥哥不限,姐姐也不限!

New_bug 2003-08-19 01:51:47
关于网络信息的获取?[所有的问题都需要在程序中解决。]
目的:从其它网页中获取目标信息。
问题:如何通过一个网址信息判断拥有数据的真实网址?如何从一个网址判断目标网址的各种useagent,contenttype,contentlanguage,method等内容?当目标信息在frame中时,如何通过先有网址获取frame中的特定网址?
最最重要的问题:如何模拟鼠标右键的察看源文件功能?

谢谢各位解答:)
...全文
77 36 打赏 收藏 转发到动态 举报
写回复
用AI写文章
36 条回复
切换为时间正序
请发表友善的回复…
发表回复
New_bug 2003-08-24
  • 打赏
  • 举报
回复
谢谢大家,有好的解决方案一定贴出,以答谢大家的热心帮助!
cnhgj 2003-08-21
  • 打赏
  • 举报
回复
呵呵!其实不难,主要是麻烦,获取数据流后要分析html代码,然后取出你想要的就可以了
superxp88 2003-08-21
  • 打赏
  • 举报
回复
gz
hotnoodle 2003-08-21
  • 打赏
  • 举报
回复
学习
lansluo 2003-08-21
  • 打赏
  • 举报
回复
多谢blackcatiii(能教我做框架设计吗) 兄。
楼主,我明白了,你明白了没有?
New_bug 2003-08-21
  • 打赏
  • 举报
回复
不过大家如果有什么其他的方法或者其他的想法,多多益善:)
New_bug 2003-08-21
  • 打赏
  • 举报
回复
大家快点发啊,本周结贴!
多谢blackcatiii(能教我做框架设计吗)
to lansluo(最后一个女巫)
俺终于明白辣:)
cbenny 2003-08-20
  • 打赏
  • 举报
回复
up
zjw19 2003-08-20
  • 打赏
  • 举报
回复
up
amoxicillin1030 2003-08-20
  • 打赏
  • 举报
回复
我来看拉。。。。可我不会
lansluo 2003-08-20
  • 打赏
  • 举报
回复
不是很明白你的意思:比如参数列表是这样cc=23&cz=可得机
把中文参数联接成字符串---是不是说把上书的作为一个字符串,不放在url后面,不经过任何编码,但是用header.add方法加上取
blackcatiii 2003-08-20
  • 打赏
  • 举报
回复
不好意思,刚才的有错误:)
把中文参数连接成字符串后设置HttpWebRequest的ContentLength属性为字符串长度;再设置ContentType为"application/x-www-form-urlencoded";再将字符串用Headers.Add(字符串)添加到Header里去,后面的步骤就不说了。
blackcatiii 2003-08-20
  • 打赏
  • 举报
回复
试试把中文参数连接成字符串后添加到HttpWebRequest的ContentLength属性里,再设置HttpWebRequest的Method为GET或POST(根据要提交给网页的Form的性质),然后按asakao(allai)的方法可以得到返回的HTML源代码再做后继处理。
zhoulanga 2003-08-20
  • 打赏
  • 举报
回复
顶一下
lansluo 2003-08-20
  • 打赏
  • 举报
回复
问题:
1:htm类型的,没有<form></form>得页面如何获取源代码?
2:如果该网页只接收中文参数,当使用HttpWebRequest变量时,中文参数会自动在uri中进行Base64编码。这样,目标网页就没有接收到正确的带参地址
blackcatiii 2003-08-20
  • 打赏
  • 举报
回复
如果目标网页需要直接传中文,不进行UrlEncode,那就把GetWeb里的HttpUtility.UrlEncode方法去掉。直接传参数原文进去。
对不同网站,有些是要utf-8编码,有些是要gb2312编码,有些网站的参数编码方式也不同一般,你要根据各种情况分析,比较复杂的说:)
这还只是前期工作,后面取得内容后的分析更繁重,而且很难找到什么好办法,郁闷吧,呵呵。
blackcatiii 2003-08-20
  • 打赏
  • 举报
回复
干脆写段代码给你看吧,通过程序登陆java-cn.com网站:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;

namespace test
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(16, 0);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.textBox1.Size = new System.Drawing.Size(880, 560);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(904, 581);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox1});
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
string strValue = "userlx=java&username=你在java-cn.com的用户名&password=你在java-cn.com的密码&cookies=30&login=登录"; //连接参数,采用Post方式传递

textBox1.Text = GetWeb("http://www.java-cn.com/pub/checklogin.jsp?where=login",true,strValue);

}

private string GetWeb(string url,bool isPost,string strValue)
{
HttpWebRequest request;

StringBuilder UrlEncoded = new StringBuilder();
Char[] reserved = {'?', '=', '&'};
int i=0, j;
while(i<strValue.Length)
{
j=strValue.IndexOfAny(reserved, i);
if (j==-1)
{
UrlEncoded.Append(HttpUtility.UrlEncode(strValue.Substring(i, strValue.Length-i)));
break;
}
UrlEncoded.Append(HttpUtility.UrlEncode(strValue.Substring(i, j-i)));
UrlEncoded.Append(strValue.Substring(j,1));
i = j+1;
}
//对参数编码:UrlEncode

if (isPost)
{
//POST方式提交表单,要设置Method、ContentType、ContentLength
request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.AllowAutoRedirect = true;
byte[] SomeBytes = Encoding.GetEncoding("gb2312").GetBytes(UrlEncoded.ToString());
request.ContentLength = SomeBytes.Length;
Stream newStream = request.GetRequestStream();
newStream.Write(SomeBytes, 0, SomeBytes.Length);//把参数用流对象写入request对象中
newStream.Close();
}
else
{
//GET方式提交表单
request = (HttpWebRequest)WebRequest.Create(url + "?" + UrlEncoded.ToString());
}


HttpWebResponse response = (HttpWebResponse)request.GetResponse();//获得服务器响应对象
Stream resStream = response.GetResponseStream();//转成流对象
StreamReader sr = new StreamReader(resStream, Encoding.GetEncoding("gb2312"));

string strtext = "";
Char[] read = new Char[256];
int count = sr.Read( read, 0, 256 );
while (count > 0)
{
String str = new String(read, 0, count);
strtext += str;
count = sr.Read(read, 0, 256);
}//读取内容
sr.Close();

return strtext;
}
}
}
win911 2003-08-19
  • 打赏
  • 举报
回复
up
bborn 2003-08-19
  • 打赏
  • 举报
回复
来学习的 我也关注
smartcreater 2003-08-19
  • 打赏
  • 举报
回复
看Tcp/IP
加载更多回复(16)

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧