我正在尝试使用urlencode转换字符串: <a href="<?php print 'search.php?query='.quote_replace(addmarks($search_results['did_you_mean'])).'&search=1'?>">
实际上,我想实现一个搜索引擎.
|-www
|- index.php
|- search directory
|- search.php
|- header.html
|- search_form.html
|- search_result.html
|- footer.html
Run Code Online (Sandbox Code Playgroud)
search.php includes header.html,search_form.html,search_result.html etc.
我使用以下方法访问search.php: localhost/index.php/?page=search
search_form.html包含要搜索的按钮.它使用:调用search.php <form action="index.php/?page=search" method="get">.我不确定它是否正确.
提交搜索请求后,search.php调用search_result.html显示结果.search_result.html中的代码:
<a href="<?php print 'search.php?query='.quote_replace(addmarks($search_results['did_you_mean'])).'&search=1'?>"><?php print $search_results['did_you_mean_b']; ?>
它似乎应该工作,但在我点击搜索按钮后,结果网址是index.php/?query=&search=1.而且我认为应该如此index.php/?page=search/?query=&search=1.
所以,我尝试使用urlencode来解决它.我不知道这个想法是否正确.
如何使用.NET(VB或C#)轻松地将字符串编码为utf8?例如,我需要编码一个像"This(is)my string"这样的字符串,结果应该是一个字符串"This +%28is%29 + my + string".
TIA
J.P
下面是这个特定文章文件夹的 .htaccess 文件。我的问题是这些 url 在被 php 脚本接收时都拆分了 $_GET 变量。
这两个 url 都创建了这个 $_GET 数组:
Array ( [article] => test- [-cake] => [folder] => none )
Run Code Online (Sandbox Code Playgroud)
Options +FollowSymLinks
RewriteEngine On
RewriteBase /food-and-diet/
RewriteRule ^.+(/css/.+)$ $1 [L]
RewriteRule ^.+(/js/.+)$ $1 [L]
RewriteRule ^.+(/images/.+)$ $1 [L]
RewriteRule ^\index.html$ index.php [NC,L]
Rewriterule ^articles/?$ index.php?index=$1&article=none&folder=none [NC,L]
Rewriterule ^articles/([^.^/]+)/?$ index.php?article=none&folder=$1 [NC,L]
RewriteRule ^articles/([^/]+)\.jpg$ articles/$1.jpg [L]
RewriteRule ^articles/([^/]+)\.gif$ articles/$1.gif [L]
RewriteRule ^articles/([^/]+)\.png$ articles/$1.png [L]
Rewriterule ^articles/([^/]+)\.html$ index.php?article=$1&folder=none [NC,L]
RewriteRule ^articles/([^.^/]+)/([^/]+)\.jpg$ articles/$1/$2.jpg [L]
RewriteRule ^articles/([^.^/]+)/([^/]+)\.gif$ articles/$1/$2.gif …Run Code Online (Sandbox Code Playgroud) 我在发送POST数据时遇到问题,包括密码字段中的"+"字符,
string postData = String.Format("username={0}&password={1}", "anyname", "+13Gt2");
Run Code Online (Sandbox Code Playgroud)
我正在使用HttpWebRequest和webbrowser来查看结果,当我尝试使用HttpWebRequest从我的C#WinForms 登录到POST数据到网站时,它告诉我密码不正确.(在源代码[richTexbox1]和webBrowser1中).尝试使用我的另一个帐户,它不包含'+'字符,它允许我正确登录(使用字节数组并将其写入流)
byte[] byteArray = Encoding.ASCII.GetBytes(postData); //get the data
request.Method = "POST";
request.Accept = "text/html";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close(); //this works well if user does not includes symbols
Run Code Online (Sandbox Code Playgroud)
从这个问题我发现这HttpUtility.UrlEncode()是逃避非法字符的解决方案,但我无法找到如何正确使用它,我的问题是,在对我的POST数据进行url编码后urlEncode()如何正确地将数据发送到我的请求?
这就是我一直在尝试HOURS让它发挥作用,但没有运气,
第一种方法
string urlEncoded = HttpUtility.UrlEncode(postData, ASCIIEncoding.ASCII);
//request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = urlEncoded.Length;
StreamWriter wr = new StreamWriter(request.GetRequestStream(),ASCIIEncoding.ASCII);
wr.Write(urlEncoded); …Run Code Online (Sandbox Code Playgroud) 我知道他们 2 会在发送到服务器之前对 URL 进行编码,但是这样做的原因是什么。
我之前从未在我的项目中使用过 encode 函数,一切都很顺利。
所以我很好奇我们在什么情况下需要使用它们,如果不使用会出现什么问题。
我已经阅读了有关 python(v2) urlencode 的其他帖子,但没有找到这个问题。
如果我有多个变量,但都具有相同的名称,我该如何使用 urlencode(如果这是正确的工具)?所以说网址是:
http://path.com/a?var=earth&var=wind&var=fire
如果我定义这个:
url = 'http://path.com/a?'
query_args = {'var': 'earth',
'var': 'wind',
'var': 'fire'}
encoded_args = urllib.urlencode(query_args, doseq=True)
print url + encoded_args
Run Code Online (Sandbox Code Playgroud)
似乎 urlencode 只返回最后一个定义的“var”:
我怎样才能得到所有var的编码?
/Detail?entitytype=2&searchtype=2&id=1749495&start=101&end=200
Run Code Online (Sandbox Code Playgroud)
是UTF-8还是Unicode?我已经尝试了两种,但它们都不起作用.Java中是否有可以解码的函数?