问题查询字符串中的斜线 [英] Problem with slash within a query string
问题描述
我使用WebRequest类做出一些站点的请求。查询字符串包含一个斜杠(/),这导致通过该网站进行切割的网址,因为它没有看到它作为查询字符串的一部分。
I'm using the WebRequest class to make a request to some site. The query string contains a slash (/), which cause to the url to be cut by the site, because it doesn't see it as part of the query string.
查询字符串是:我的PARAMS /用斜线
The query string is: "my params / separated by slash".
请求:
var request = WebRequest.Create(
"http://www.somesime.com/q-my+params+%2f+separated+by+slash"
);
我缺少的是什么?
What I missing?
编辑:
所有的答案后,这里的更新:
After all answers here are update:
我错了查询字符串,它不是实际的查询字符串,但URL应该看(没有?):
I was wrong about query string, it's not actually query string, but the url should look (without "?"):
"http://www.somesime.com/q-my+params+%2f+separated+by+slash"
该网址http://www.somesime.com/q-my+params+%2f+separated+by+slash是Server.UrlEn code方法的结果。在code:
The url "http://www.somesime.com/q-my+params+%2f+separated+by+slash" is result of Server.UrlEncode method. The code:
var url = "http://www.somesime.com/q-" +
Server.UrlEncode(@"my params / separated by slash");
编辑2:
如果我把产生的URL到浏览器,一切正常。
但是,如果我通过WebRequest类运行它,该URL结果它被称为没有/用斜线分开的一部分
EDIT 2: If I place the resulting url into a browser, everything works. But if I run it through WebRequest class, the url results as it was called without "/ separated by slash" part
推荐答案
您需要看看阿帕奇AllowEn codedSlashes选项
You need to have a look at apaches AllowEncodedSlashes option
http://httpd.apache.org/文档/ 2.0 / MOD / core.html#allowen codedslashes
您应该能够通过的.htaccess,使这个或httpd_conf
You should be able to enable this through .htaccess or httpd_conf
这篇关于问题查询字符串中的斜线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!