473,320 Members | 1,990 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,320 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


Nov 16 '05 #1
3 1494
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


Nov 16 '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


Nov 16 '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>
Nov 16 '05 #4

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

Similar topics

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. ...
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: 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 =...
1
by: Mr Flibble | last post by:
OK I logon to a web site and I manage to get an SMSESSION cookie that I then store in a variable called _session (a class scoping variable). I do this by calling a logon URL and setting a cookie...
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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.