|
I am writing an application that will give me content of a web page.
I wrote following code for that.
WebRequest objRequest = HttpWebRequest.Create("url");
StreamReader sr = new StreamReader(objRequest.GetResponse().GetResponseStream());
string result = sr.ReadToEnd();
sr.Close();
This works fine if the url i am connecting to does not require to login.
I want to read content of a web page which requires first to put in login details (user/password) to get access.
for that i tried with
WebRequest objRequest = HttpWebRequest.Create("url");
NetworkCredential netCred = new NetworkCredential("User","Password");
objRequest.Credentials = netCred;
StreamReader sr = new StreamReader(objRequest.GetResponse().GetResponseStream());
string result = sr.ReadToEnd();
sr.Close();
No success with this as well. It gets the contents of log in page and not the one specified by url.
Can anyone help me with this?
How to Read contents of a webpage which requires to login first.
Thanks,
AksharRoop
|
|
|
|
|
AksharRoop wrote: I want to read content of a web page which requires first to put in login details
Do you log in through a web page, or does your browser display a login dialog for you?
If you use forms based login (i.e. through a web page) then you will have to find a way to replicate that as if the user was actually sitting at the browser.
|
|
|
|
|
I have already logged on to that site using web-browser.
I am writing an automated application that will read the content of web page and send it across.
for that i will be logging on to web-page through browser and at some particular time my application will be triggered to read and send data.
I tried with the code posted but it did not work for me.
I am using Mozilla browser. Is there any way to connect to the same session?
|
|
|
|
|
AksharRoop wrote: I have already logged on to that site using web-browser.
I would imagine then that it stores a cookie with the session information. You would have to replicate the contents of that cookie and send it with your request in your application in order to get to the password protected areas.
AksharRoop wrote: Is there any way to connect to the same session?
Not that I know of. You would have to replicate the session (probably using the above)
|
|
|
|
|
I am new to C#. Could you please put code snippet?
|
|
|
|
|
A recent thread[^] got me wondering, when is the goto command actually acceptable? I've always steered clear of it and it seems to be an easy one to stay away from. I think the last time I used goto must have been somewhere around 1984, using GWBasic so I've kind of forgotten of its existence.
But if it's part of the C# language it must be there for a reason. Could anyone give me examples of where you would be willing to use the goto statement?
|
|
|
|
|
I can think of three cases:
1. An error condition is discovered when you're in deeply-nested multiple loops, and you need to stop this processing and go on to something else. A goto will exit this cleanly.
2. In grad school I worked on a system that created programs automatically by wiring together mechanisms (task-specific source-code procedures). Goto statements were exactly what was needed for sequencing their invocation.
3. A compiler bug prevented the normal sequence of execution, and time was running out. A goto was used to force control to the next statement to be executed, solving the problem in time.
I haven't had to use a goto in over 15 years. They can easily make your program's flow more complex than it has to be. And complex programs are harder to debug, and less reliable. 99.99% of the time you can avoid gotos.
|
|
|
|
|
switch
{
case a:
break;
case b:
goto default;
case c:
break;
default:
break;
}
while (someConditionA)
{
while (someConditionB)
{
foreach (something in other)
{
if (exit condition)
goto Label_ExitLoops;
}
}
}
Label_ExitLoops:
Only two situations I ever use it for. Deeply nested loops could be exited with a series of flags, but I think the goto is a lot cleaner and more efficient.
|
|
|
|
|
The use of "goto" is only acceptable when you're telling someone where to go ("hell" is the typical destination suggestion).
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
So we should have labels called hell?
|
|
|
|
|
When studying, one of my lecturers forced us all to write 1'000 times on a paper: "I shall never use goto". In his opinion this way we would remember it. He was correct.
|
|
|
|
|
int count = 0;
loop:
if (count < 1000)
{
Console.WriteLine("I shall never use goto");
count++;
goto loop;
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
|
Fantastic.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
2000 goto's will suffice for this month, please stop it (that may take another goto, break would not work in your loop).
|
|
|
|
|
I don't think that I have used a GOTO since 8 bit Atari BASIC in the mid '80s.
I think that a goto would be acceptable if it would clearly make the code simpler and easier to read. However, if you really has such a complex structure that a goto would actually improve the code, it should probably be completely rewritten instead.
Another sitaution where a goto might be acceptable is for performance reasons. However, it's not very often that a goto would actually improve performance much.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
When programming in assembly or a related language that lacks higher level control constructs.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
when they are called branch or jump, it is an entirely different matter.
|
|
|
|
|
I was thinking that myself earlier - I don't use assembly at all on the PC, but I use it exclusively for PIC programming where goto and/or bra (and their variants bnz etc) depending on the family I'm using are invaluble. I'm sure alot of our lovely gotoless code ends up being assembled down to jump instructions.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
I especially like the "skip next instruction if..." kind of instructions, such as BTFSS on PIC 16F84.
They may well flabbergast these high-level programmers that frown on a simple goto...
|
|
|
|
|
I've recently moved from the 16F to 18F series and in the last couple of weeks because of peripheral requirements the dsPIC30F series. You should have a look at the number of variations that are available for those instruction types (the PIC I'm currently using[^] - secion 18-2). Most of these are 2 cycles (8 clocks) including the branch, the non branching instructions are mostly 1 cycle. Running at 30MIPS some code can perform (almost) as well as a PC running at supposedly several GHz because of the inefficient code and wasted clock cycles.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
You should use goto whenever you need it (this is a rather subtle point).
The problem is that unexperienced programmers (aka 'Senior Developers') will misuse it. That's the reason for the draconian sentences against the poor goto statement.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
IMHO, Goto is only acceptable during the next Ice Age and every 3rd Ice Age thereafter.
Seriously, I haven't used one in over 8 years, and don't plan on doing so anytime soon. If your app, data model, algorithm, ..., is designed correctly, you shouldn't need one.
Dewald wrote: Could anyone give me examples of where you would be willing to use the goto statement?
Have you ever seen the little window stickers of the kid peeing on some company logo?? Put the Goto in place of the logo...
|
|
|
|
|
Dave Kreskowiak wrote: Have you ever seen the little window stickers of the kid peeing on some company logo?? Put the Goto in place of the logo...
Ok, that is definitely an acceptable use of goto.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi
I've a DLL that basically refers 2 another .Net DLLs, with the given situation is it possible for us to create only one TLB file using (TLBEXP.EXE) with all dependencies?
Thanks in advance ...
|
|
|
|