我有一些看起来类似于此的代码:
<h:outputLink value="#{bean.url}" />
Run Code Online (Sandbox Code Playgroud)
但输出包含链接href中的撇号,而不是 URL编码.
我做错了什么或者是outputLink的正常行为吗?提前致谢.
(JBoss 4.2,Java 1.6)
两者之间有什么区别:
HttpUtility.UrlEncode("some string with é and ? and stuff")
HttpUtility.UrlEncode("some string with é and ? and stuff", Encoding.UTF8)
HttpUtility.UrlEncode( "some string with é and ? and stuff", Encoding.Default )
Run Code Online (Sandbox Code Playgroud)
结果是:
some+string+with+%c3%a9+and+%ce%b2+and+stuff
some+string+with+%c3%a9+and+%ce%b2+and+stuff
some+string+with+%e9+and+%df+and+stuff
Run Code Online (Sandbox Code Playgroud)
在测试时,我得到前两个相同的结果,所以我可以安全地假设UTF8是默认值,除非指定,或者可以在不同的系统上有所不同吗?
我有一些unicode转义序列的示例,如下所示:
%u00e9(é)
相当确定paypal在他们的IPN请求中发送了它.为什么.NET不像这样编码?
mod_rewrite似乎在我将它转换为$ _REQUEST之前转换了plus的符号,我不知道要修复它...
RewriteRule ^invite/([a-zA-Z0-9\-\+\/]+)/?$ invite.php?key=$1 [L,QSA]
Run Code Online (Sandbox Code Playgroud)
例如,我将此输入到我的URL中,
http://mywebsite/invite/xPo8lUEXpqg8bKL%2B32o6yIOK
Run Code Online (Sandbox Code Playgroud)
我明白了
xPo8lUEXpqg8bKL 32o6yIOK
Run Code Online (Sandbox Code Playgroud)
但如果我输入此请求而不通过mod_rewrite,
http://mywebsite/invite.php?key=xPo8lUEXpqg8bKL%2B32o6yIOK
Run Code Online (Sandbox Code Playgroud)
我得到了我想要的东西,
xPo8lUEXpqg8bKL+32o6yIOK
Run Code Online (Sandbox Code Playgroud)
我能做什么?或者是我只能使用它们而不是两者兼而有之?
谢谢.
我们实现了一个HTTP身份验证连接,用C#编码Uri.EscapeDataString().
我正在尝试创建一个与C#版本完全相同的java测试应用程序,但URLEncoder.encode(string, "UTF-8")添加了与C#Uri.EscapeDataString()函数不完全相同的其他编码.
什么是等效的编码方法?
我有一个java程序,它应该从URL读取文件(URL位置是IIS网站下的虚拟目录;下面,在我的初始测试中,我将其视为任何其他文件系统位置).不幸的是,所有需要读取的文件的路径都包含一个目录名中的井号(#),而我无法改变它.当(作为测试)我将它指向路径中没有英镑符号的位置时,该程序可以很好地工作.
我首先从传递给程序的字符串创建一个URL.对于像/Documents/#2012/09/11(文件是Windows共享)这样的文件路径,如果我在命令行上传递了这样的路径,我可以让程序成功处理:
file://serverIPaddress/Documents/\%232012/09/07/16/DOC4671179.DOC
Run Code Online (Sandbox Code Playgroud)
也就是说,用英镑符号手动编码为%23,并且反斜杠转移%23的%.
获取该URL只有一行:
URL url = new URL(filePath); // filePath is passed in
Run Code Online (Sandbox Code Playgroud)
但是这个程序不会被这样的编码路径用勺子喂食,所以我不得不弄清楚如何以编程方式对井号进行编码.继续找到关于如何编码URL以避免java中的特殊字符的好建议,我使用多参数构造函数创建了一个URI(我将已传递给程序的参数分解为三个单独的参数以适应该更改) .这是看起来像:
URI uri = new URI(protocol, host, filePath, null); // all values are passed in
Run Code Online (Sandbox Code Playgroud)
这恰好编码了英镑符号; 我的URI是:
file://serverIPaddress/Documents/%232012/09/07/16/DOC4671179.DOC
Run Code Online (Sandbox Code Playgroud)
但是如果没有前面的反斜杠%23,程序就会回来Connection refused,大概是因为它没有反斜杠的好处而误解了路径.
所以我想,好吧,我会自己添加反斜杠.我创建了相同的URI,提取了它的rawPath,并且通过一些字符串操作,在%23前面加了一个反斜杠.然后我使用新字符串创建了一个新的URI:
URI uri = new URI(protocol, host, filePath, null); // all values are passed in
String rawPath = uri.getRawPath();
int pctPos = rawPath.indexOf("%");
String escaped = new String("\\");
String firstPart = rawPath.substring(0,pctPos);
String secondPart …Run Code Online (Sandbox Code Playgroud) 试图从Python中移植一段代码:
my_input = "this&is£some text"
encoded_input = urllib.quote_plus(str(my_input))
Run Code Online (Sandbox Code Playgroud)
...到JavaScript:
var my_input = "this&is£some text";
encoded_input = encodeURIComponent(my_input);
Run Code Online (Sandbox Code Playgroud)
细微差别在于urllib.quote_plus()将空格转换+为%20 (链接).只是想知道是否有人可以提供任何想法.目前正在与...
var my_input = "this&is£some text";
encoded_input = encodeURIComponent(my_input).replace(/%20/g,'+');
Run Code Online (Sandbox Code Playgroud) 这是一个写出XML文件的测试应用程序.
为什么路径中的空格被转换为%20?
public class XmlTest
{
public static void main(String[] args)
{
String filename = "C:\\New Folder\\test.xml";
try {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
DOMSource source = new DOMSource(doc);
File xmlFile = new File(filename);
if (xmlFile.exists())
{
xmlFile.delete();
}
StreamResult result = new StreamResult(xmlFile);
transformer.transform(source, result);
}
catch (ParserConfigurationException ex)
{
ex.printStackTrace();
}
catch (TransformerException tfe)
{
tfe.printStackTrace();
} …Run Code Online (Sandbox Code Playgroud) 有没有办法在Python中urlencode/urldecode一个字符串?我想强调我想要一个字符串,而不是一个字符串dict.我知道这样做的功能dict.我可以轻松地构造一个函数来为字符串做这个,但我宁愿不必构造自己的函数.Python内置了这个功能吗?
(对Python 2.7和3.3的答案将不胜感激.)
我想用特殊字符编码URL.在我的情况下它是:( š, ä, õ, æ, ø它不是一个有限的列表).
urllib2.quote(symbol)给出了非常奇怪的结果,这是不正确的.这些符号怎么可以编码?
我在java中为HTTP PUT方法生成了一个预先签名的S3 URL.
稍微修改过的URL版本:
https://s3.amazonaws.com/somebucket/pre-signed-url-key-2?AWSAccessKeyId=BKIAIQ6H5Z7BG6KZ2ZUA&Expires=1425617244&Signature=GWcRM5ZIrAKnMJBsxyfm%2F9fyuBk%3D
我知道它是一个有效的预签名网址,因为我可以使用它curl来上传文件
curl -v --upload-file somefile.txt "https://s3.amazonaws.com/somebucket/pre-signed-url-key-2?AWSAccessKeyId=BKIAIQ6H5Z7BG6KZ2ZUA&Expires=1425617244&Signature=GWcRM5ZIrAKnMJBsxyfm%2F9fyuBk%3D"
当我尝试使用以下Javascript将文件上传到同一URL时:
function ajaxUsingPresignedUrlPut() {
$.ajax({
url: presignedURLPUT,
type: 'PUT',
data: 'blah blah blah',
success: function () {
console.log('Uploaded data successfully.');
}
}).done(function (data) {
console.log("DONE : " + data);
}).fail(function (e, r) {
console.log("FAIL");
});
}
Run Code Online (Sandbox Code Playgroud)
我得到403状态和responseText
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message><AWSAccessKeyId>BKIAIQ6H5Z7BG6KZ2ZUA</AWSAccessKeyId><StringToSign>PUT
application/x-www-form-urlencoded; charset=UTF-8
1425617244
/somebucket/pre-signed-url-key-2</StringToSign><SignatureProvided>GWcRM5ZIrAKnMJAsxyfm/9fyuAk=</SignatureProvided><StringToSignBytes>50 55 54 0a 0a 61 …Run Code Online (Sandbox Code Playgroud)