473,399 Members | 3,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Problems with WebRequest

Hi,

I am trying to download a image that is generated by PHP using
HttpWebRequest, I believe the server uses cookies to generate the image, but
I keep getting the error image from the server.

Can anyone help?

The code I am using is :-

Uri myUrl = new
Uri("http://www.kingsofchaos.com/recruit.php?uniqid=84y75898");
HttpWebRequest myReq = (HttpWebRequest) WebRequest.Create(myUrl);
myReq.CookieContainer = new CookieContainer();

myReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET
CLR 1.0.3705)";
myReq.KeepAlive = true;

HttpWebResponse myResponse = (HttpWebResponse) myReq.GetResponse();
Console.WriteLine("\nThe HttpHeaders are \n\n\tName\t\tValue\n{0}",
myResponse.Headers);

string mySession = myResponse.Headers["Set-Cookie"];

myResponse.Close();
myReq = (HttpWebRequest)
WebRequest.Create("http://www.kingsofchaos.com/imageclick.php");
myReq.CookieContainer = new CookieContainer();
myReq.Headers["Cookie"] = mySession;

Console.WriteLine("\nThe HttpHeaders are \n\n\tName\t\tValue\n{0}",
myReq.Headers);

myReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET
CLR 1.0.3705)";
myReq.KeepAlive = true;

myResponse = (HttpWebResponse) myReq.GetResponse();
pictureBox1.Image = Image.FromStream(myResponse.GetResponseStream());
pictureBox1.Size = pictureBox1.Image.Size;

myResponse.Close();
Thanks in advance

Adam


Jul 21 '05 #1
3 1671
Hi Adam:

You should not have to set the Cookie header yourself. Using:

CookieContainer cookies = new CookieContainer();

You can than assign the cookies instance to both webrequests and the
cookies should be sent appropriately. For example, use the following
line on both instances of myReq:

myReg.CookieContainer = cookies;

HTH,

--
Scott
http://www.OdeToCode.com

On Sat, 21 Aug 2004 14:05:21 +0100, "Adam Stirk" <.> wrote:
Hi,

I am trying to download a image that is generated by PHP using
HttpWebRequest, I believe the server uses cookies to generate the image, but
I keep getting the error image from the server.

Can anyone help?

The code I am using is :-

Uri myUrl = new
Uri("http://www.kingsofchaos.com/recruit.php?uniqid=84y75898");
HttpWebRequest myReq = (HttpWebRequest) WebRequest.Create(myUrl);
myReq.CookieContainer = new CookieContainer();

myReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET
CLR 1.0.3705)";
myReq.KeepAlive = true;

HttpWebResponse myResponse = (HttpWebResponse) myReq.GetResponse();
Console.WriteLine("\nThe HttpHeaders are \n\n\tName\t\tValue\n{0}",
myResponse.Headers);

string mySession = myResponse.Headers["Set-Cookie"];

myResponse.Close();
myReq = (HttpWebRequest)
WebRequest.Create("http://www.kingsofchaos.com/imageclick.php");
myReq.CookieContainer = new CookieContainer();
myReq.Headers["Cookie"] = mySession;

Console.WriteLine("\nThe HttpHeaders are \n\n\tName\t\tValue\n{0}",
myReq.Headers);

myReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET
CLR 1.0.3705)";
myReq.KeepAlive = true;

myResponse = (HttpWebResponse) myReq.GetResponse();
pictureBox1.Image = Image.FromStream(myResponse.GetResponseStream());
pictureBox1.Size = pictureBox1.Image.Size;

myResponse.Close();
Thanks in advance

Adam


Jul 21 '05 #2
The problem I have got is the website returns 3 cookies in the header, but
when I call

myReg.CookieContainer.GetCookies();

I only get 2, when there should be 3 as myResponse.Headers["Set-Cookie"]
returns 3 cookies.

The example I supplied is the actual code I am trying to use, if you run it
your self you will see this.

HTH

Adam
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:p1********************************@4ax.com...
Hi Adam:

You should not have to set the Cookie header yourself. Using:

CookieContainer cookies = new CookieContainer();

You can than assign the cookies instance to both webrequests and the
cookies should be sent appropriately. For example, use the following
line on both instances of myReq:

myReg.CookieContainer = cookies;

HTH,

--
Scott
http://www.OdeToCode.com

On Sat, 21 Aug 2004 14:05:21 +0100, "Adam Stirk" <.> wrote:
Hi,

I am trying to download a image that is generated by PHP using
HttpWebRequest, I believe the server uses cookies to generate the image, butI keep getting the error image from the server.

Can anyone help?

The code I am using is :-

Uri myUrl = new
Uri("http://www.kingsofchaos.com/recruit.php?uniqid=84y75898");
HttpWebRequest myReq = (HttpWebRequest) WebRequest.Create(myUrl);
myReq.CookieContainer = new CookieContainer();

myReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; ..NETCLR 1.0.3705)";
myReq.KeepAlive = true;

HttpWebResponse myResponse = (HttpWebResponse) myReq.GetResponse();
Console.WriteLine("\nThe HttpHeaders are \n\n\tName\t\tValue\n{0}",
myResponse.Headers);

string mySession = myResponse.Headers["Set-Cookie"];

myResponse.Close();
myReq = (HttpWebRequest)
WebRequest.Create("http://www.kingsofchaos.com/imageclick.php");
myReq.CookieContainer = new CookieContainer();
myReq.Headers["Cookie"] = mySession;

Console.WriteLine("\nThe HttpHeaders are \n\n\tName\t\tValue\n{0}",
myReq.Headers);

myReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; ..NETCLR 1.0.3705)";
myReq.KeepAlive = true;

myResponse = (HttpWebResponse) myReq.GetResponse();
pictureBox1.Image = Image.FromStream(myResponse.GetResponseStream());
pictureBox1.Size = pictureBox1.Image.Size;

myResponse.Close();
Thanks in advance

Adam


Jul 21 '05 #3

"Adam Stirk" <.> wrote in message
news:41**********************@ptn-nntp-reader03.plus.net...
Hi,

I am trying to download a image that is generated by PHP using
HttpWebRequest, I believe the server uses cookies to generate the image, but I keep getting the error image from the server.

Can anyone help?

The code I am using is :-

Uri myUrl = new
Uri("http://www.kingsofchaos.com/recruit.php?uniqid=84y75898");
HttpWebRequest myReq = (HttpWebRequest) WebRequest.Create(myUrl);
myReq.CookieContainer = new CookieContainer();

myReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET
CLR 1.0.3705)";
myReq.KeepAlive = true;

HttpWebResponse myResponse = (HttpWebResponse) myReq.GetResponse();
Console.WriteLine("\nThe HttpHeaders are \n\n\tName\t\tValue\n{0}",
myResponse.Headers);

string mySession = myResponse.Headers["Set-Cookie"];

myResponse.Close();
myReq = (HttpWebRequest)
WebRequest.Create("http://www.kingsofchaos.com/imageclick.php");
myReq.CookieContainer = new CookieContainer();
myReq.Headers["Cookie"] = mySession;

Console.WriteLine("\nThe HttpHeaders are \n\n\tName\t\tValue\n{0}",
myReq.Headers);

myReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET
CLR 1.0.3705)";
myReq.KeepAlive = true;

myResponse = (HttpWebResponse) myReq.GetResponse();
pictureBox1.Image = Image.FromStream(myResponse.GetResponseStream());
pictureBox1.Size = pictureBox1.Image.Size;

myResponse.Close();
Thanks in advance

Adam

Here is an vb example of getting the graphic and displaying it as an image
on a website. Maybe it will help you.
Mike

<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing" %>
<%@ import Namespace="System.Drawing.Imaging" %>

<html>
<script language="vb" runat="server">
Sub Page_Load(sender as object, e as eventargs)
Dim myURL as Uri = new Uri("http://www.kingsofchaos.com/imageclick.php")
Dim myReq as HttpWebRequest = WebRequest.Create(myUrl)

myReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET
CLR 1.0.3705)"
myReq.KeepAlive = true
Response.ContentType = "image/jpeg"
Dim myResponse as HttpWebResponse = myReq.GetResponse()
Dim mynewimage as system.drawing.image =
system.drawing.image.fromstream(myResponse.GetResp onseStream())
mynewimage.Save(Response.OutputStream, ImageFormat.Jpeg)

end sub
</script>
<body>

</body>
</html>
Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Andreas Håkansson | last post by:
Hello, I'm using the WebRequest class to download a few files of a webserver. I use async io to fecth the data. My problem is that the first file works like a charm, and the second file loads...
3
by: Adam Stirk | last post by:
Hi, I am trying to download a image that is generated by PHP using HttpWebRequest, I believe the server uses cookies to generate the image, but I keep getting the error image from the server. ...
3
by: Sean Chapman | last post by:
ok, heres the problem.. i have an asp.net page that im using to kind of relay information back and forth. So on the Page_Load i make a request to a webservice and return some xml back to the first...
1
by: GSK | last post by:
This one has me stumped: I am using HttpWebRequest to resolve an external URL (that outputs an XML string). It works fine on my dev machine (W2K), and used to work on my production machine...
0
by: Glenn Venzke | last post by:
I am trying to invoke a web service from an ASP.net page using the WebRequest object to an HTTP post. The web service is basically a print manager that prints sets of documents based an an invoice...
2
by: Tyler | last post by:
I am using httpwebrequest to do a screen scrape. This works great on my development box, but does not on the production box. Here is the code. Dim webRequest As HttpWebRequest =...
3
by: eSolTec, Inc. 501(c)(3) | last post by:
Thank you in advance for any and all assistance. I'm trying to create a call to a web page to validate and register software. The code I'm using is: Private Sub OK_Click(ByVal sender As...
2
by: Kenneth Wong | last post by:
Anyone did it before. Please advise. Yahoo mail, Gmail, Regular Hotmail work...
0
by: Solius | last post by:
I have been struggling for 4 days to write a connection to an XML REST API. I can't figure out what is wrong with my code that it won't connect propertly. The goal is to make a web service that...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.