gpt4 book ai didi

java - HttpClient 2.0。参数 "codified"

转载 作者:行者123 更新时间:2023-12-02 08:23:27 25 4
gpt4 key购买 nike

我必须使用 HttpClient 2.0(不能使用任何更新的版本),并且我遇到了下一个问题。当我使用该方法(在这种情况下为 post)时,它将参数“编码”为十六进制 ASCII 代码,并且“空格”变成“+”(接收者不想要的东西)。

有人知道避免这种情况的方法吗?

非常感谢。

最佳答案

甚至您的浏览器也会这样做,将空格字符转换为+。看到这里http://download.oracle.com/javase/1.5.0/docs/api/java/net/URLEncoder.html

它对 URL 进行编码,转换为类似 UTF-8 的字符串。

When encoding a String, the following rules apply:

  • The alphanumeric characters "a" through "z", "A" through "Z" and "0" through "9" remain the same.
  • The special characters ".", "-", "*", and "_" remain the same.
  • The space character " " is converted into a plus sign "+".
  • All other characters are unsafe and are first converted into one or more bytes using some encoding scheme. Then each byte is represented by the 3-character string "%xy", where xy is the two-digit hexadecimal representation of the byte. The recommended encoding scheme to use is UTF-8. However, for compatibility reasons, if an encoding is not specified, then the default encoding of the platform is used.

此外,请参阅此处 http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1

  1. Control names and values are escaped. Space characters are replaced by +', and then reserved characters are escaped as described in [RFC1738], section 2.2: Non-alphanumeric characters are replaced by%HH', a percent sign and two hexadecimal digits representing the ASCII code of the character. Line breaks are represented as "CR LF" pairs (i.e., `%0D%0A').

  2. The control names/values are listed in the order they appear in the document. The name is separated from the value by =' and name/value pairs are separated from each other by&'.

<小时/>

如果您不想编码,请回答您的问题。我猜,URLDecoder.decode将帮助您撤消编码的字符串。

关于java - HttpClient 2.0。参数 "codified",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5014339/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com