cms9651
December 15, 2012, 8:24pm
1
Image of the remote site
Hello guys!
I need your help.
This is code of my net page (C#).
I don’t have error but in the output of webpage I don’t see the image of the remote site, but I see an icon undefined…
How can i do it?
Can someone test my code?
please
Any help?
Thank you.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="CallRemote_Default" %>
<!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 runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Literal ID="Literal1" runat="server" Mode="passthrough">
<img alt="" src="<img alt="" src="http://www.meteowebcam.it/export_reg.php?reg=Toscana&day=0"/>"/></asp:Literal>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
public partial class CallRemote_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Literal1.Text = getHtml("http://www.meteowebcam.it/export_reg.php?reg=Toscana&day=0");
}
public string getHtml(string url)
{
try
{
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.Method = "GET";
WebResponse myResponse = myRequest.GetResponse();
StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
string result = sr.ReadToEnd();
sr.Close();
myResponse.Close();
return result;
}
catch (Exception exception)
{
return "The following error occurred: " + exception;
}
}
}
cpradio
December 15, 2012, 8:36pm
2
Look at your HTML, specifically
<img alt="" src="<img alt="" src="http://www.meteowebcam.it/export_reg.php?reg=Toscana&day=0"/>"/></asp:Literal>
What do you see that is wrong? You have an image tag within the src attribute of another image…
cms9651
December 15, 2012, 8:45pm
3
thank you for reply.
I tried this but I have the same problem…
I don’t see the image of the remote site, but I see an icon undefined…
<asp:Literal ID="Literal1" runat="server" Mode="passthrough">
<img alt="" src="http://www.meteowebcam.it/export/toscana_1355547600_0.jpg"/>
</asp:Literal>
cpradio
December 16, 2012, 12:49am
4
After the page loads, what is the final output? As your Page_Load is going to overwrite what is contained within the Literal. I’m curious as to what that may be.
cms9651
December 16, 2012, 11:41am
5
thank you for help.
as a matter a fact are authorized to use the image… [:)]
this is the solution:
Grab the image directly instead of the surrounding HTML
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Drawing;
public partial class CallRemote_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string url = "http://www.meteowebcam.it/export/toscana_1355612400_0.jpg";
string file_name = Server.MapPath(".") + "\\\ oscana_1355612400_0.jpg";
save_file_from_url(file_name, url);
}
public string getHtml(string url)
{
try
{
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.Method = "GET";
WebResponse myResponse = myRequest.GetResponse();
StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
string result = sr.ReadToEnd();
sr.Close();
myResponse.Close();
return result;
}
catch (Exception exception)
{
return "The following error occurred: " + exception;
}
}
public void save_file_from_url(string file_name, string url)
{
byte[] content;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
using (BinaryReader br = new BinaryReader(stream))
{
content = br.ReadBytes(500000);
br.Close();
}
response.Close();
FileStream fs = new FileStream(file_name, FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
try
{
bw.Write(content);
}
finally
{
fs.Close();
bw.Close();
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="CallRemote_Default" %>
<!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 runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<a href="http://www.meteowebcam.it/meteo/Toscana.html">
<asp:Image ID="Image1" runat="server" ImageUrl="/WebApplication1/CallRemote/toscana_1355612400_0.jpg" /></a>
</div>
</form>
</body>
</html>