I am doing a project in screen scrapping. In which I am extracting data and images from two websites. I have no problem with extracting data from both website. The problem which I am facing is, in the case of images. In one website the images are stored in folder, so I captured the path and stored it. In the other one, images path is given as an ASP file, which I am not able to download. I used Webclient object to catch the response, but as it creating a new request I think it is redirecting to an error login page and I am not getting the required image. If I tried to write the byte and see the result it is showing some html content. I think it is the content in error page. Both are password protected sites.
My Code:
byte[] b;
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(strCarImages[i].ToString());
WebResponse myResp = myReq.GetResponse();
Stream stream = myResp.GetResponseStream();
//int i;
using (BinaryReader br = new BinaryReader(stream))
{
//i = (int)(stream.Length);
b = br.ReadBytes(500000);
br.Close();
}
myResp.Close();
WriteBytesToFile(strImage, b);
//return b;
static public void WriteBytesToFile(string fileName, byte[] content)
{
FileStream fs = new FileStream(fileName, FileMode.Create);
BinaryWriter w = new BinaryWriter(fs);
try
{
w.Write(content);
}
finally
{
fs.Close();
w.Close();
}
}
Expecting your valuable reply.