473,568 Members | 3,014 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.kingsofchao s.com/recruit.php?uni qid=84y75898");
HttpWebRequest myReq = (HttpWebRequest ) WebRequest.Crea te(myUrl);
myReq.CookieCon tainer = 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 = (HttpWebRespons e) myReq.GetRespon se();
Console.WriteLi ne("\nThe HttpHeaders are \n\n\tName\t\tV alue\n{0}",
myResponse.Head ers);

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

myResponse.Clos e();
myReq = (HttpWebRequest )
WebRequest.Crea te("http://www.kingsofchao s.com/imageclick.php" );
myReq.CookieCon tainer = new CookieContainer ();
myReq.Headers["Cookie"] = mySession;

Console.WriteLi ne("\nThe HttpHeaders are \n\n\tName\t\tV alue\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 = (HttpWebRespons e) myReq.GetRespon se();
pictureBox1.Ima ge = Image.FromStrea m(myResponse.Ge tResponseStream ());
pictureBox1.Siz e = pictureBox1.Ima ge.Size;

myResponse.Clos e();
Thanks in advance

Adam


Jul 21 '05 #1
3 1680
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.CookieCon tainer = 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.kingsofchao s.com/recruit.php?uni qid=84y75898");
HttpWebReque st myReq = (HttpWebRequest ) WebRequest.Crea te(myUrl);
myReq.CookieCo ntainer = new CookieContainer ();

myReq.UserAgen t = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET
CLR 1.0.3705)";
myReq.KeepAliv e = true;

HttpWebRespons e myResponse = (HttpWebRespons e) myReq.GetRespon se();
Console.WriteL ine("\nThe HttpHeaders are \n\n\tName\t\tV alue\n{0}",
myResponse.Hea ders);

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

myResponse.Clo se();
myReq = (HttpWebRequest )
WebRequest.Cre ate("http://www.kingsofchao s.com/imageclick.php" );
myReq.CookieCo ntainer = new CookieContainer ();
myReq.Header s["Cookie"] = mySession;

Console.WriteL ine("\nThe HttpHeaders are \n\n\tName\t\tV alue\n{0}",
myReq.Headers) ;

myReq.UserAgen t = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET
CLR 1.0.3705)";
myReq.KeepAliv e = true;

myResponse = (HttpWebRespons e) myReq.GetRespon se();
pictureBox1.Im age = Image.FromStrea m(myResponse.Ge tResponseStream ());
pictureBox1.Si ze = pictureBox1.Ima ge.Size;

myResponse.Clo se();
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.CookieCon tainer.GetCooki es();

I only get 2, when there should be 3 as myResponse.Head ers["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.c om...
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.CookieCon tainer = 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.kingsofchao s.com/recruit.php?uni qid=84y75898");
HttpWebReque st myReq = (HttpWebRequest ) WebRequest.Crea te(myUrl);
myReq.CookieCo ntainer = new CookieContainer ();

myReq.UserAgen t = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; ..NETCLR 1.0.3705)";
myReq.KeepAliv e = true;

HttpWebRespons e myResponse = (HttpWebRespons e) myReq.GetRespon se();
Console.WriteL ine("\nThe HttpHeaders are \n\n\tName\t\tV alue\n{0}",
myResponse.Hea ders);

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

myResponse.Clo se();
myReq = (HttpWebRequest )
WebRequest.Cre ate("http://www.kingsofchao s.com/imageclick.php" );
myReq.CookieCo ntainer = new CookieContainer ();
myReq.Header s["Cookie"] = mySession;

Console.WriteL ine("\nThe HttpHeaders are \n\n\tName\t\tV alue\n{0}",
myReq.Headers) ;

myReq.UserAgen t = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; ..NETCLR 1.0.3705)";
myReq.KeepAliv e = true;

myResponse = (HttpWebRespons e) myReq.GetRespon se();
pictureBox1.Im age = Image.FromStrea m(myResponse.Ge tResponseStream ());
pictureBox1.Si ze = pictureBox1.Ima ge.Size;

myResponse.Clo se();
Thanks in advance

Adam


Jul 21 '05 #3

"Adam Stirk" <.> wrote in message
news:41******** **************@ ptn-nntp-reader03.plus.n et...
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.kingsofchao s.com/recruit.php?uni qid=84y75898");
HttpWebRequest myReq = (HttpWebRequest ) WebRequest.Crea te(myUrl);
myReq.CookieCon tainer = 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 = (HttpWebRespons e) myReq.GetRespon se();
Console.WriteLi ne("\nThe HttpHeaders are \n\n\tName\t\tV alue\n{0}",
myResponse.Head ers);

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

myResponse.Clos e();
myReq = (HttpWebRequest )
WebRequest.Crea te("http://www.kingsofchao s.com/imageclick.php" );
myReq.CookieCon tainer = new CookieContainer ();
myReq.Headers["Cookie"] = mySession;

Console.WriteLi ne("\nThe HttpHeaders are \n\n\tName\t\tV alue\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 = (HttpWebRespons e) myReq.GetRespon se();
pictureBox1.Ima ge = Image.FromStrea m(myResponse.Ge tResponseStream ());
pictureBox1.Siz e = pictureBox1.Ima ge.Size;

myResponse.Clos e();
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="Syst em.Net" %>
<%@ Import Namespace="Syst em.IO" %>
<%@ Import Namespace="Syst em.Drawing" %>
<%@ import Namespace="Syst em.Drawing.Imag ing" %>

<html>
<script language="vb" runat="server">
Sub Page_Load(sende r as object, e as eventargs)
Dim myURL as Uri = new Uri("http://www.kingsofchao s.com/imageclick.php" )
Dim myReq as HttpWebRequest = WebRequest.Crea te(myUrl)

myReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET
CLR 1.0.3705)"
myReq.KeepAlive = true
Response.Conten tType = "image/jpeg"
Dim myResponse as HttpWebResponse = myReq.GetRespon se()
Dim mynewimage as system.drawing. image =
system.drawing. image.fromstrea m(myResponse.Ge tResponseStream ())
mynewimage.Save (Response.Outpu tStream, ImageFormat.Jpe g)

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
2151
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 about 99%. The problem is that i *know* that BeginRead is called for the second file (over and over again) but the callback is never called for
3
1499
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. Can anyone help? The code I am using is :-
3
1959
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 calling app. now... i wrote a test app to try it out, but i cannot get the proper data from it. It always says the the ContentLength is -1 so my my...
1
1475
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 (W2K3). It seems that now, for some reason, the connection cannot be established. The error logged is: The underlying connection was closed: Unable to...
0
1180
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 number passed as an argument. The first time I invoke it, it works fine. However when I do a second invokation, the http request hangs until it...
2
3321
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 = CType(webRequest.Create(LOGIN_URL), HttpWebRequest) webRequest.Proxy = System.Net.GlobalProxySelection.GetEmptyWebProxy webRequest.KeepAlive = False
3
9574
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 System.Object, ByVal e As System.EventArgs) Handles OK.Click Dim WebRequest As HttpWebRequest Dim instance As HttpWebRequest =...
2
1645
by: Kenneth Wong | last post by:
Anyone did it before. Please advise. Yahoo mail, Gmail, Regular Hotmail work...
0
1514
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 connects directly to the REST API. When I code it as a front end doing a form post it works fine, but I can't code the VB on the backend to do the same...
0
7605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7917
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7962
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6277
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5501
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.