' For a GET request
Dim webC As New WebClient
Dim strResponse As String = ""
For Each strUrl As String In ListBox1.Items
strResponse = webC.DownloadString(strUrl)
Do Until webC.IsBusy = False
Application.DoEvents()
Loop
webC.Dispose()
Next
' For a POST request
Dim webC As New WebClient
Dim strResponse As String = ""
Dim strPostData As String = "your post data here"
For Each strUrl As String In ListBox1.Items
strResponse = webC.UploadString(strUrl, strPostData)
Do Until webC.IsBusy = False
Application.DoEvents()
Loop
webC.Dispose()
Next
Code:' For a GET request Dim webC As New WebClient Dim strResponse As String = "" For Each strUrl As String In ListBox1.Items strResponse = webC.DownloadString(strUrl) Do Until webC.IsBusy = False Application.DoEvents() Loop webC.Dispose() NextCode:' For a POST request Dim webC As New WebClient Dim strResponse As String = "" Dim strPostData As String = "your post data here" For Each strUrl As String In ListBox1.Items strResponse = webC.UploadString(strUrl, strPostData) Do Until webC.IsBusy = False Application.DoEvents() Loop webC.Dispose() Next
Hope that helps!
Thanks inaga,
However when the list of urls is bigger than1 I get the following error:
InvalidCastException was unhandled
Conversion from type 'Match' to type 'String' is not valid.
Any ideas?
Dim webC As New WebClient
Dim strResponse As String = ""
Dim strUrl As String = ""
For Each itemMatch As Match In ListBox1.Items
strUrl = itemMatch.ToString
strResponse = webC.DownloadString(strUrl)
Do Until webC.IsBusy = False
Application.DoEvents()
Loop
webC.Dispose()
Next
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Add(textBox1.Text);
}
private void button2_Click(object sender, EventArgs e)
{
foreach (String item in listBox1.Items)
{
MessageBox.Show(ViewWebsite.Connect(item));
}
}
}
public class ViewWebsite
{
public static string Connect(String url)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
//Set Request Paramaters here.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader responseStream = new StreamReader(response.GetResponseStream());
return responseStream.ReadToEnd();
}
}
foreach (String item in listBox1.Items)
{
MessageBox.Show(ViewWebsite.Connect(item));
}
foreach (Match item in listBox1.Items)
{
MessageBox.Show(ViewWebsite.Connect(item.Value));
}
I don't want to hijack this thread but what book or which place for me learn stuffs like this (writing application that dealing with websites in vb.net). I have read few books about vb.net for beginner but they only show how to build desktop applications, not handling with websites.
Thanks a lot
as far as i know there are no books.
have to figure it out as you go using google and your imagination.
Public Sub New()
InitializeComponent()
End Sub
Private Sub button1_Click(sender As Object, e As EventArgs)
listBox1.Items.Add(textBox1.Text)
End Sub
Private Sub button2_Click(sender As Object, e As EventArgs)
For Each item As [String] In listBox1.Items
MessageBox.Show(ViewWebsite.Connect(item))
Next
End Sub
Public Class ViewWebsite
Public Shared Function Connect(url As [String]) As String
Dim request As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
'Set Request Paramaters here.
Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
Dim responseStream As New StreamReader(response.GetResponseStream())
Return responseStream.ReadToEnd()
End Function
End Class
For Each item As [String] In listBox1.Items
MessageBox.Show(ViewWebsite.Connect(item))
Next
For Each item As Match In listBox1.Items
MessageBox.Show(ViewWebsite.Connect(item.Value))
Next