不久前,我注意到当将映射编码name: value为时'application/x-www-form-urlencoded,它会呈现类似的内容(这里我使用 Python):
>>> from urllib import urlencode
>>> urlencode({'hello': '', 'blabla': 'hihi'})
'blabla=hihi&hello='
Run Code Online (Sandbox Code Playgroud)
但是解析(至少使用Python)只是删除具有空值的对:
>>> from urlparse import parse_qs
>>> parse_qs('blabla=hihi&hello=')
{'blabla': ['hihi']}
Run Code Online (Sandbox Code Playgroud)
那么...这是标准行为吗?www-form-urlencoded在哪里可以找到有关如何解析的参考?我用 google 搜索了一段时间,找到了 uris 的 RFC、表单的 W3c 文档等等,但没有找到关于如何处理空值的信息。有人可以给我指点吗???
为了获得有效的 XML RSS 提要,我需要对查询字符串中包含“&”的链接进行 url 编码。但是,当用户在浏览器中查看 RSS 源时,链接不会被解码,因此当他们单击链接时,结果页面会被破坏,因为查询字符串参数没有被正确读取。
例如
http://www.mysite.com?foo1=bar1&foo2=bar2,在浏览器中查看为http://www.mysite.com?foo1=bar1%26foo2=bar2时,参数 foo1 被视为 bar1%26foo2 =bar2 而不是将水果和饮料分成两个单独的参数。
将我的链接包装在标签中而不对其进行编码是可行的,但是在我的 MRSS 提要中,我有一些字段,例如包含标签会破坏 XML。
我怎样才能正确编码我的链接以便一切正常?
我正在尝试使用来自 node js API 的 mandrill 发送邮件。
只要我的“下载链接”没有“危险”字符,例如:“/”和“?”,我就成功发送了以下内容
发送以下内容,但“链接”无处可循:
var downloadLink =(encodeURIComponent('itms-services://c')
var text = [
"We are excited to send you a version of our app",
"You can download it here: <a href=\""+downloadLink+"\">link</a> thats it.",
].join('<br>')
console.log(text)
var message = {
"html": text,
"subject": "New App!",
"from_email": "Hello@d.com",
"from_name": "D Guys",
"to": [{
"email": mail,
//"name": "Recipient Name",
"type": "to"
}],
"headers": {
"Reply-To": "message.reply@example.com"
},
"important": false,
"track_opens": true,
"track_clicks": true,
"auto_text": null,
"auto_html": false,
"inline_css": null,
"url_strip_qs": …Run Code Online (Sandbox Code Playgroud) 我的脚本在网站上搜索歌曲,但是当有空格时它不会搜索,您必须添加下划线。我想知道是否有办法用下划线替换我的空格。你能不能用我现在的代码告诉我怎么做?
set search to text returned of (display dialog "Enter song you wish to find" default answer "" buttons {"Search", "Cancel"} default button 1)
open location "http://www.mp3juices.com/search/" & search
end
Run Code Online (Sandbox Code Playgroud) 无法准备NSURL带有包含表情符号图标的字符串的对象。
当我尝试NSURL使用以下方法形成时:
let urlString = "http://www.example.com/"
let URL = NSURL(string: urlString)
Run Code Online (Sandbox Code Playgroud)
URL 返回值为 nil,而浏览器可以使用相同的 urlString 打开有效网页。
我想在 UIWebView 中打开它。那么有没有像如何正确编码以满足 NSURL 要求之类的想法?
任何指针将不胜感激。
更新: 当我尝试使用以下字符串准备 NSURL 对象时:
let encodedURLString = urlString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
它工作得很好,因为stringByAddingPercentEscapesUsingEncoding()方法将非法 url 字符转换为合法表示。但这已被弃用。
stringByAddingPercentEncodingWithAllowedCharacters()可以使用它的替代方法,但必须在不同的 url 组件上调用它,例如:
// host: "www.example.com", path: "/"
host.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLHostAllowedCharacterSet())
path.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLPathAllowedCharacterSet())
Run Code Online (Sandbox Code Playgroud)
如何从字符串中获取 url 组件(即主机、路径等),因为当我尝试创建 NSURL/NSURLComponents 时,它返回 nil。(原因是格式错误的 url 字符串。)??
之间有什么区别
HttpUtility.UrlPathEncode(params);
Run Code Online (Sandbox Code Playgroud)
和
HttpUtility.UrlEncode(params);
Run Code Online (Sandbox Code Playgroud)
我查看了 MSDN 页面
https://msdn.microsoft.com/en-us/library/system.web.httputility.urlpathencode(v=vs.110).aspx
https://msdn.microsoft.com/en- us/library/system.web.httputility.urlencode(v=vs.110).aspx
但它只告诉你不要使用 UrlPathEncode,它没有说明有什么区别。
我正在尝试从 PHP 程序对 Influx db 进行 API 调用。要提出的卷曲请求是 -
curl -G 'http://localhost:8086/query?pretty=true' --data-urlencode "q=SHOW MEASUREMENTS"
Run Code Online (Sandbox Code Playgroud)
我坚持使用的 PHP 代码是 -
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://localhost:8086/query?pretty=true",
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache"
),
));
Run Code Online (Sandbox Code Playgroud)
我不确定应该在哪个curl_setopt_array发送q=SHOW MEASUREMENTS
我正在处理一个项目,但在使用 encodeURIcomponent 函数时遇到了一些问题。该站点是一个社交媒体内容库,它允许我将副本存储在 CMS 中,并将其显示在页面上,并带有链接和按钮以共享到社交媒体站点。我正在为 Twitter 组件苦苦挣扎,需要一些帮助。这是我的代码:
function tweetClick() {
var url = "http://urlfromcms.com";
var text = "I'm getting this text dynamically from the CMS too.";
window.open('http://twitter.com/share?url='+encodeURIComponent(url)+'&text='+encodeURIComponent(text), '');
} Run Code Online (Sandbox Code Playgroud)
<a class="shareitbutton w-button" href="#" target="_blank" title="Tweet" onclick="tweetClick(); return false;">Tweet It!</a>Run Code Online (Sandbox Code Playgroud)
这就像一个有一个问题的冠军。如果副本有与号、撇号、引号等,那么它也会被编码,并且需要编辑推文,这违背了目的。如何编码以在 twitter 需要的空间中获得 %20 但不理会我的&符号和撇号?
任何帮助将不胜感激!
我正在尝试在 Angular 7 中对查询参数值进行编码。但是当我的查询参数值包含任何特殊字符时,我得到 400 Bad Request 状态代码
失败的请求 URL: http://localhost/api/67/cardvalues?parentcardvalues=STONE&parentcardvalues=STONE%20AGE
但是,当我的查询参数值不包含任何特殊字符时,我得到 200 OK 状态代码。
请求成功地址: http://localhost/api/67/cardvalues?parentcardvalues=STONE&parentcardvalues=STONE
预期的请求 url 必须像 http://localhost/cardvalues?parentcardvalues=VALUE1&parentcardvalues=VALUE2
下面是我的代码,
parentcardvalues=["STONE","STONE AGE"]
let myparams = new HttpParams();
if(parentcardvalues.length != 0)
parentcardvalues.forEach((value) => {
myparams = myparams.append( 'parentcardvalues', encodeURIComponent(value) );
});
this.http.get(this.baseUrl + 'api/67/cardvalues', {params: myparams});
Run Code Online (Sandbox Code Playgroud)
Swagger 规范是,
卷曲
curl -X GET "http://localhost/api/cardvalues?parentcardvalues=STONE&parentcardvalues=STONE%20AGE" -H "accept: application/json"
Run Code Online (Sandbox Code Playgroud)
请求网址
http://localhost/api/cardvalues?parentcardvalues=STONE&parentcardvalues=STONE%20AGE
Run Code Online (Sandbox Code Playgroud) 我是 Kotlin 的新手,我正在尝试对具有查询参数的 url 进行 url 编码。
private const val HREF = "date?July 8, 2019"
private const val ENCODED_HREF = print(URLEncoder.encode(HREF, "utf-8"))
private const val URL = "www.example.com/"+"$ENCODED_HREF"
Run Code Online (Sandbox Code Playgroud)
错误:常量“val”的类型为“Unit”。只允许使用原语和字符串private const val ENCODED_HREF