为不同的URL格式击中URL [英] Hitting URLs for different formats of URLs
本文介绍了为不同的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"进行了比较: ^ ](您可以检查源的代码以查看使用的技术).
我下载的两个答案有些不同.不同之处在于某些JavaScript的主体,其中包含许多整数-它们是不同的.我可以解释一下.在服务器端生成HttpWebResponse形式的输出.与静态网页一样,它可能只是存储在服务器上的某些固定文件的副本,但是在Google搜索的情况下,涉及一些服务器端代码来生成响应.自然.现在,通过HTTP请求,服务器端代码知道了引荐来源网址,因此服务器代码的行为可能有所不同.在服务器端代码中考虑"if"运算符.
如果遇到异常,则必须做错了事.可能有数百万个原因.太糟糕了,您没有共享代码和异常信息转储. 问问题时应始终这样做.
对于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 usingHttpWebRequest
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屋!
查看全文