Hi all,
I am trying to display tweets from multiple users at the same time. I tried storing the urls in an array then looping through the array to get the urls and send them to " timeLineRequest = (HttpWebRequest)WebRequest.Create(urls);" but it only stores the last url. I am using a foreach for this. What am I doing wrong?
Coding in c#
Thanks in advance
Loading

Dhirendra MisraRank #4,173 · 360 reputationPosted Jan 7, 2014, 6:37 PM EST
Please share the piece of code where you are storing the URLs in an array, I think there will be some issue.
Thanks
Avuya MxoliRank #7,940 · 231 reputationPosted Jan 7, 2014, 8:30 PM EST
Dhirendra MisraRank #4,173 · 360 reputationPosted Jan 8, 2014, 10:42 PM EST
I am not sure I am getting you properly. Are you getting value of variable "timeLineRequest" is as last URL because you are overwriting the value of variable "timeLineRequest" in the loop.
Hence the last URL value your are getting in variable when foreach exits.
I tried the same and I got output:
HttpWebRequest timeLineRequest;
string[] arrUrls = { "http://www.google.com", "http://www.contoso.com/default.html", "http://www.msn.com" };
foreach (string url in arrUrls)
{
timeLineRequest = (HttpWebRequest)WebRequest.Create(url);
Console.WriteLine(timeLineRequest.Host);
}
Output:
www.google.com
www.contoso.com
www.msn.com
Avuya MxoliRank #7,940 · 231 reputationPosted Jan 8, 2014, 11:20 PM EST
I only get statuses for DebonairsPizza
Dhirendra MisraRank #4,173 · 360 reputationPosted Jan 9, 2014, 12:48 AM EST
Collection can be prepared using List<>
within foreach {}
List
timeLineResponse = (HttpWebResponse)timeLineRequest.GetResponse();
listTimeLineResponse.Add(timeLineResponse);
Avuya MxoliRank #7,940 · 231 reputationPosted Jan 9, 2014, 1:03 AM EST
Avuya MxoliRank #7,940 · 231 reputationPosted Jan 9, 2014, 1:21 AM EST
List
Dhirendra MisraRank #4,173 · 360 reputationPosted Jan 9, 2014, 5:06 PM EST