Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi,

I am developing an application. In this, i am using HttpWebRequest and HttpWebResponse classes for hitting URLs. But its only works for the correct URLs like http://www.google.com

if the user typed http://google.com or simply google.com or https://www.google.com (secure)
it got exception.


how could i solve this issue, any idea?

regards
harish
Posted
Comments
Sergey Alexandrovich Kryukov 30-Nov-11 13:43pm    
How can you hope for help if you did not share neither exception information, nor any code sample?
I've just explained some general ideas, something you should always understand.
--SA

1 solution

If has nothing to do with your client; these URLs are treated as different by the servers. So you cannot assume the same results.

I've just compared "http://www.google.com" vs "http://google.com" using my HttpDownloader utility using HttpWebRequest and HttpWebResponse I shared here at CodeProject: how to download a file from internet[^] (you can check the source code of it to see the techniques used).

The two responses I downloaded were a bit different. The difference was in the body of some JavaScript which contained a number of integer numbers — they were different. I can explain that. The output in the form of HttpWebResponse is generated on the server side. It could be just a copy of some fixed file stored on the server as in the case of static Web pages, but in case of Google search some server-side code is involved to generate to response. Naturally. Now, the referrer URL is known to the server-side code through the HTTP request, so the server code can behave differently. Think of "if" operator in the server-side code.

If you got an exception, you must be doing something wrong. There can be millions of reasons. Too bad you did not share your code and the dump of exception information. You should always do it when asking questions.

As to HTTPS, this is a different protocol. Let's assume some Web site uses both HTTP and HTTPS. In this case, "http://www.domain.tld/directory/page.html" and "https://www.domain.tld/directory/page.html" could be completely different unrelated pages.

—SA
 
Share this answer
 
v2
Comments
Harish Kumar Bansal 1-Dec-11 7:07am    
But if we hit url in a real browser, it always shows the same web page.
can i do this in my project. if yes ,then how?
Sergey Alexandrovich Kryukov 8-Dec-11 3:03am    
Not always. There a millions of examples. Most typically:

http://www.domail.tld/resourse vs. http://domail.tld/resourse -- usually same resource, same thing about '/' at the end.

http://www.domail.tld/resourse vs. https://www.domail.tld/resourse -- usually different resources, could be logically and visually identical though, but different -- one is unsafe another is safe.

You have no control over this, the server does. So, a client side should be on a conservative side.

--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900