خواندن مقادیر یک سایت با استفاده از WebRequest در سی شارپ

بازدید26.6kپست ها3آخرین فعالیت10 سال پیش
0
0

سلام
من قبلا یک سوال راجع به همین سوالی که میخوام بپرسم ، پرسیده بودم و جواب هم دادید اما اون واسه WebBrowser بود ، همون سوال رو کپی میکنم :

من یکHTML ساختم و آپلود کردم

کد HTML :

[CSHARP]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>ads</title> </head> <body> <!-- Begin Close Right-Click --> <SCRIPT TYPE="text/javascript"> //Disable right click script function clickIE() {if (document.all) {(message);return false;}} function clickNS(e) {if (document.layers||(document.getElementById&&!document.all)) { if (e.which==2||e.which==3) {(message);return false;}}} if (document.layers) {document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;} else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;} document.oncontextmenu=new Function("return false") </SCRIPT> <!-- End Close Right-Click --> <!-- Begin Ads -->

<img src="http://localhost/1/1.gif" type="ad1" id="ad1" /><br/>

<img src="http://localhost/1/2.gif" type="ad2" id="ad2" alt="Advertisment 1" /> <!-- End Ads --> <!-- Begin Passage --> <p id="pashmak1">Softafzar</p> <p id="pashmak2">Softafzar.net</p> <!-- End Passage --> </body> </html>[/CSHARP]

میخوام بدونم که چطوری میتونم با استفاده از WebRequest اینکار رو انجام بدم که عکس ها رو توی یک Picture box و متن ها رو توی label1,2 نشون بدم ؟

حالا اگه اون سافت افزار ها آیدی نداشتن چیکار باید کرد ؟

سوال بعدی اینه که چطوری میشه با استفاده از WebRequest واسه برنامه قسمت آپدیت گذاشت؟

ممنون

0

درود ادرس پستو بده

0

بفرما :

http://www.softafzar.net/thread908.html/

واسه به روز رسانی نرم افزار هم من الکی یه چیزی ساختم و تست هم کردم و جواب هم گرفتم ، شما هم یک نظر بدید :

[CSHARP]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.NetworkInformation;
using System.Reflection;
using System.Diagnostics;

namespace WindowsFormsApplication21
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private string Upd = "";
private void button1_Click(object sender, EventArgs e)
{
try
{
WebClient webClient = new WebClient();
string str1 = webClient.DownloadString("http://localhost/3/index.txt");
string str2 = String.Format("{0}", AssemblyVersion);
string strA = str1.Replace(".", "");
string strB = str2.Replace(".", "");
int i1 = int.Parse(strA);
int i2 = int.Parse(strB);
if (i1 == i2)
{
label1.Text = "No New Version";
label2.Text = "Your Version : " + str2;
label3.Text = "Last Version : " + str1;
label1.Show();
label2.Show();
label3.Show();
}
if (i1 > i2)
{
label1.Text = "New Version is Released for Download";
label2.Text = "Your Version : " + str2;
label3.Text = "Last Version : " + str1;
linkLabel1.Text = "Click For Download new Version";

                WebClient webClient1 = new WebClient();
                Upd = webClient.DownloadString("http://localhost/3/index2.txt");

            }
        }
        catch { }
    }
    public string AssemblyVersion
    {
        get
        {
            return Assembly.GetExecutingAssembly().GetName().Version.ToString();
        }
    }

    private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
    {
        try
        {
            Process.Start(Upd);
        }
        catch { }
    }
}

}
[/CSHARP]

0

اینو امتحان کن

[CSHARP]
//Using WebClient Class
WebClient client = new WebClient();
string reply = client.DownloadString("http://127.0.0.1/pashmak.html");
//MessageBox.Show(reply);
//Using WebClient Class

        if (reply.Contains("<p id=\"pashmak1\""))
        {
            String filteredString = Regex.Match(reply, "<p id=\"pashmak1\"(.*)</p>").ToString();
            MessageBox.Show(filteredString);
            //...
        }

        if (reply.Contains("http://localhost/1/1.gif"))
        {
            var request = WebRequest.Create("http://localhost/1/1.gif");

            using (var response = request.GetResponse())
            using (var stream = response.GetResponseStream())
            {
                pictureBox1.Image = Bitmap.FromStream(stream);
            }
        }

[/CSHARP]

سوال برنامه نویسی دارید؟

ندونستن عیب نیست، نپرسیدن چرا!

خوش آمدید

برای طرح سوال، ایجاد بحث و فعالیت در سایت نیاز است ابتدا وارد حساب کاربری خود شوید. در صورتی که هنوز عضو سایت نیستید میتوانید در عرض تنها چند ثانیه ثبت نام کنید.