为不同的URL格式击中URL [英] Hitting URLs for different formats of URLs

查看:75
本文介绍了为不同的URL格式击中URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在开发一个应用程序.在此,我使用 HttpWebRequest HttpWebResponse 类来访问URL.但是它仅适用于正确的URL,例如 http://www.google.com

如果用户键入 http://google.com 或只是键入 google.com https://www.google.com (安全)
它有异常.


我怎么能解决这个问题呢?

问候
harish

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

推荐答案

如果与您的客户无关?服务器将这些URL视为不同.因此,您不能假定结果相同.

我刚刚使用我在CodeProject上在这里共享的HttpWebRequest和HttpWebResponse使用HttpDownloader实用程序将"http://www.google.com"与"http://google.com"进行了比较:
如果遇到异常,则必须做错了事.可能有数百万个原因.太糟糕了,您没有共享代码和异常信息转储. 问问题时应始终这样做.

对于HTTPS,这是一个不同的协议.假设某些网站同时使用HTTP和HTTPS.在这种情况下,"http://www.domain.tld/directory/page.html"和"https://www.domain.tld/directory/page.html"可能是完全不同的无关页面.

—SA
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


这篇关于为不同的URL格式击中URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆