472,985 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Requesting a XML document programatically

I have a site that i can request directly
from my browser's URL field by typing:

http://localhost/Search.aspx?qwert

and i wonder how i could obtain the very
same text that is rendered into the area
of my browser but assign it to a string
variable.

The pseudocode for it as follows.
string url = http://localhost/Search.aspx;
Connection c = new Connection (url);
c.Request();
string xml = c.GetXmlContentsString();

I've been googling but haven't had luck
so i guess it's something awfully basic
and simple.

Konrad Viltersten
Jul 10 '08 #1
8 1150
K Viltersten,

Have you looked at the WebClient class in the System.Net namespace? It
will do exactly what you want. If you need more control over the request
you are making, you can use the HttpWebRequest/HttpWebResponse classes in
the same namespace.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"K Viltersten" <tm**@viltersten.comwrote in message
news:6d************@mid.individual.net...
>I have a site that i can request directly
from my browser's URL field by typing:

http://localhost/Search.aspx?qwert

and i wonder how i could obtain the very
same text that is rendered into the area
of my browser but assign it to a string
variable.

The pseudocode for it as follows.
string url = http://localhost/Search.aspx;
Connection c = new Connection (url);
c.Request();
string xml = c.GetXmlContentsString();

I've been googling but haven't had luck
so i guess it's something awfully basic
and simple.

Konrad Viltersten


Jul 10 '08 #2
Have you looked at the WebClient class in the System.Net namespace? It
will do exactly what you want. If you need more control over the request
you are making, you can use the HttpWebRequest/HttpWebResponse classes in
the same namespace.
I've been trying out some things with the
namespace you mentioned. Perhaps i'm not far
off the right code but this far, it's not
reading the stream as i want it to. This is the
code that i run.

string url = "http://localhost/Search.aspx?qwert";

WebRequest request = WebRequest.Create(url);

request.Method = "POST";

request.ContentType = "text/xml";

StreamReader reader = new StreamReader(request.GetRequestStream());

string contents = reader.ReadToEnd();

reader.Close();

I get errors when creating the stream. Please note,

not when i READ the stream but when i CREATE the reader...

Please advise.

Konrad Viltersten
Jul 10 '08 #3
The GetRequestStream function is the one that causes the request to be sent.
Try changing the Method to GET instead of POST.
If you still get errors, post the error message. They could be due to
firewalls/proxys needing authentication or a header missing from the request
so the message is key to helping with them. They the Method change first
though and let us know.
--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"K Viltersten" wrote:
Have you looked at the WebClient class in the System.Net namespace? It
will do exactly what you want. If you need more control over the request
you are making, you can use the HttpWebRequest/HttpWebResponse classes in
the same namespace.

I've been trying out some things with the
namespace you mentioned. Perhaps i'm not far
off the right code but this far, it's not
reading the stream as i want it to. This is the
code that i run.

string url = "http://localhost/Search.aspx?qwert";

WebRequest request = WebRequest.Create(url);

request.Method = "POST";

request.ContentType = "text/xml";

StreamReader reader = new StreamReader(request.GetRequestStream());

string contents = reader.ReadToEnd();

reader.Close();

I get errors when creating the stream. Please note,

not when i READ the stream but when i CREATE the reader...

Please advise.

Konrad Viltersten
Jul 10 '08 #4
On Jul 10, 3:53*pm, "K Viltersten" <t...@viltersten.comwrote:
Have you looked at the WebClient class in the System.Net namespace? It
will do exactly what you want. If you need more control over the request
you are making, you can use the HttpWebRequest/HttpWebResponse classes in
the same namespace.

I've been trying out some things with the
namespace you mentioned. Perhaps i'm not far
off the right code but this far, it's not
reading the stream as i want it to. This is the
code that i run.
The Stream you're fetching is the *request* stream - i.e. a stream for
the data which needs to get *sent* to the web server. That's not
readable - you're meant to write into it (if you want to send up any
data).

You want the *response* stream to read from.

Jon
Jul 10 '08 #5
See this example for the proper syntax :
http://msdn.microsoft.com/en-us/libr...ebrequest.aspx

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"K Viltersten" <tm**@viltersten.comwrote in message news:6d************@mid.individual.net...
>Have you looked at the WebClient class in the System.Net namespace? It will do exactly what you want. If you need
more control over the request you are making, you can use the HttpWebRequest/HttpWebResponse classes in the same
namespace.

I've been trying out some things with the
namespace you mentioned. Perhaps i'm not far
off the right code but this far, it's not
reading the stream as i want it to. This is the
code that i run.

string url = "http://localhost/Search.aspx?qwert";

WebRequest request = WebRequest.Create(url);

request.Method = "POST";

request.ContentType = "text/xml";

StreamReader reader = new StreamReader(request.GetRequestStream());

string contents = reader.ReadToEnd();

reader.Close();

I get errors when creating the stream. Please note,

not when i READ the stream but when i CREATE the reader...

Please advise.

Konrad Viltersten


Jul 10 '08 #6
re:
!The Stream you're fetching is the *request* stream - i.e. a stream for
!the data which needs to get *sent* to the web server. That's not
!readable - you're meant to write into it (if you want to send up any data).

Exactly.

The link to the MSDN docs I just posted has correct sample code.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:80**********************************@r66g2000 hsg.googlegroups.com...
On Jul 10, 3:53 pm, "K Viltersten" <t...@viltersten.comwrote:
Have you looked at the WebClient class in the System.Net namespace? It
will do exactly what you want. If you need more control over the request
you are making, you can use the HttpWebRequest/HttpWebResponse classes in
the same namespace.

I've been trying out some things with the
namespace you mentioned. Perhaps i'm not far
off the right code but this far, it's not
reading the stream as i want it to. This is the
code that i run.
The Stream you're fetching is the *request* stream - i.e. a stream for
the data which needs to get *sent* to the web server. That's not
readable - you're meant to write into it (if you want to send up any
data).

You want the *response* stream to read from.

Jon
Jul 10 '08 #7
This is almost the exact thing i need. Only
one problem remains. Just as you, guys,
suspected, there's an issue with login.
The instance of WebClient i've created
isn't logged-in yet and that's why i get
nada from the server.

So, the question is now as follows. How can
i retrieve the current credentials from
"this" so i can copy them into my instance
of WebClient)?

The link that Juan so kindly provided, led
only to DefaultNetworkCredentials and that
can't be the currently used ones...

Regards
Konrad Viltersten


"Juan T. Llibre" <no***********@nowhere.comskrev i meddelandet
news:eY**************@TK2MSFTNGP02.phx.gbl...
See this example for the proper syntax :
http://msdn.microsoft.com/en-us/libr...ebrequest.aspx

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"K Viltersten" <tm**@viltersten.comwrote in message
news:6d************@mid.individual.net...
>>Have you looked at the WebClient class in the System.Net namespace? It
will do exactly what you want. If you need more control over the request
you are making, you can use the HttpWebRequest/HttpWebResponse classes
in the same namespace.

I've been trying out some things with the
namespace you mentioned. Perhaps i'm not far
off the right code but this far, it's not
reading the stream as i want it to. This is the
code that i run.

string url = "http://localhost/Search.aspx?qwert";

WebRequest request = WebRequest.Create(url);

request.Method = "POST";

request.ContentType = "text/xml";

StreamReader reader = new StreamReader(request.GetRequestStream());

string contents = reader.ReadToEnd();

reader.Close();

I get errors when creating the stream. Please note,

not when i READ the stream but when i CREATE the reader...

Please advise.

Konrad Viltersten



Jul 10 '08 #8
Small amendment. I know i can set the
credentials to the current ones by the
UseDefaultCredentials of my WebClient
object.

However, allthough it solves the issue
for this time, i feel like it's only a
lucky coincidence that i succeeded. I
prefer to be in full control.

Thank you this far and please advise.

Regards
Konrad Viltersten
This is almost the exact thing i need. Only
one problem remains. Just as you, guys,
suspected, there's an issue with login.
The instance of WebClient i've created
isn't logged-in yet and that's why i get
nada from the server.

So, the question is now as follows. How can
i retrieve the current credentials from
"this" so i can copy them into my instance
of WebClient)?

The link that Juan so kindly provided, led
only to DefaultNetworkCredentials and that
can't be the currently used ones...

Regards
Konrad Viltersten


"Juan T. Llibre" <no***********@nowhere.comskrev i meddelandet
news:eY**************@TK2MSFTNGP02.phx.gbl...
>See this example for the proper syntax :
http://msdn.microsoft.com/en-us/libr...ebrequest.aspx

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"K Viltersten" <tm**@viltersten.comwrote in message
news:6d************@mid.individual.net...
>>>Have you looked at the WebClient class in the System.Net namespace? It
will do exactly what you want. If you need more control over the
request you are making, you can use the HttpWebRequest/HttpWebResponse
classes in the same namespace.

I've been trying out some things with the
namespace you mentioned. Perhaps i'm not far
off the right code but this far, it's not
reading the stream as i want it to. This is the
code that i run.

string url = "http://localhost/Search.aspx?qwert";

WebRequest request = WebRequest.Create(url);

request.Method = "POST";

request.ContentType = "text/xml";

StreamReader reader = new StreamReader(request.GetRequestStream());

string contents = reader.ReadToEnd();

reader.Close();

I get errors when creating the stream. Please note,

not when i READ the stream but when i CREATE the reader...

Please advise.

Konrad Viltersten




Jul 10 '08 #9

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

Similar topics

6
by: Chris Travers | last post by:
Hi all; I am using PostgreSQL 7.4 on RedHat 9, though I don't think that is important to this problem. I am attempting to write a rule that will check to see whether certain conditions are...
0
by: Mico | last post by:
I would be very grateful for any help with the following: I currently have the code below. This opens a MS Word document, and uses C#'s internal regular expressions library to find if there is a...
0
by: sengkok | last post by:
I have developed a credit system which can deduct the credit point from the users when they are printing the document from the PC. Now I am facing another problem is how can I stop the printer to...
1
by: Wade | last post by:
Hello, I have a question regarding the creation of an email via ASP.NET. I would like the email, which is programmatically generated, to request a response receipt from the receipient, so that...
1
by: Fredrik | last post by:
How to I solve the following requirement on my application? On a generated aspx page, there should be a button "Create Document". When the user clicks this button, the application creates (on...
17
by: pbd22 | last post by:
hi. i keep getting this error. as i understand it, my xml isn't formatted correctly. the online errata suggests the standard formatting to solve this problem: element (tab) (tab) element
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
2
by: Ronald Raygun | last post by:
I have a document that is layed out in divs with ids and classes. There can be N divs of class "other" but only one div with id ="main". Only the div with id "main" should be visible. I want to...
1
by: Van Dugall | last post by:
Hello I have been writing a game in javascript which works fine but I wanted to step it up and request the data of the game from the server. I haven't really used php...all I know is from the...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.