4
Answers

WebClient has problem reading web page

shlomi gadol

shlomi gadol

9y
397
1
Hi,
 
I have problem reading web page string, This is my code. I got only "" in the result string. If you can help me it would be great.
 
you can see that the url provide something in webrowser but with webclient it doesn't return anything. if you can try it by yourself and reply with resolution.
 
thanks a lot
shlomi
 
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string url;
url = "http://www.finviz.com/screener.ashx?v=110&s=ta_topgainers&o=-price"; // This is not working
WebClient client = new WebClient();
string reply = client.DownloadString(url);
}
}
}
 
 
 
Answers (4)
0
Raja T

Raja T

NA 7.4k 6k 9y
Hi,Before you can check directly in browers url contains data or not.
 
try my sample url image file
 
System.Net.WebClient wc = new System.Net.WebClient();
byte[] raw = wc.DownloadData("http://adrenalin.myadrenalin.com/myadrenalin/images/login.jpg");
string webData = System.Text.Encoding.UTF8.GetString(raw);
 
 
It will return data. 
0
Raja T

Raja T

NA 7.4k 6k 9y
yes, it is working for me.
0
shlomi gadol

shlomi gadol

NA 36 14.2k 9y
Hi,
 
It doesn't work, i got empty array on raw.
 
did you try it? is it working for you?
 
Thanks
Shlomi
 
0
Raja T

Raja T

NA 7.4k 6k 9y
Hi try like this
 
private void button1_Click(object sender, EventArgs e)
{
string url;
url = "http://www.finviz.com/screener.ashx?v=110&s=ta_topgainers&o=-price"; // This is not working
System.Net.WebClient wc = new System.Net.WebClient();
byte[] raw = wc.DownloadData(url); 
string reply = System.Text.Encoding.UTF8.GetString(raw);
}