encodeuricomponent

How to encode URL parameters?

别来无恙 提交于 2019-11-30 07:47:26
I am trying to pass parameters to a URL which looks like this: http://www.foobar.com/foo?imageurl= and I want to pass the parameters suchas and image URL which is generated itself by another API, and the link for the image turns out as: http://www.image.com/?username=unknown&password=unknown However, when I try to use the URL: http://www.foobar.com/foo?imageurl=http://www.image.com/?username=unknown&password=unknown it doesn't work.. I have also tried using encodeURI and encodeURIComponents on the imageURL, and that too doesn't work. With PHP echo urlencode("http://www.image.com/?username

JS encodeURIComponent result different from the one created by FORM

≡放荡痞女 提交于 2019-11-29 17:36:08
I thought values entered in forms are properly encoded by browsers. But this simple test file "test_get_vs_encodeuri.html" shows it's not true: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html><head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title></title> </head><body> <form id="test" action="test_get_vs_encodeuri.html" method="GET" onsubmit="alert(encodeURIComponent(this.one.value));"> <input name="one" type="text" value="Euro-€"> <input type="submit" value="SUBMIT"> </form> </body></html> When

Firefox automatically decoding encoded parameter in url, does not happen in IE

删除回忆录丶 提交于 2019-11-29 16:57:15
问题 I am having frustration between Firefox and IE, well mostly Firefox as it is automatically decoding a parameter in the hash before I can work with it in Javascript. IE does not automatically decode the url thus not giving me reading errors. My problem is similar to this one except I am not using ASP.NET ASP.NET MVC automatically decoding JSON-encoded parameters from AJAX So if I take a url like example.com/#question=!%40%23%24%25^%26*( whereas the "!%40%23%24%25^%26*(" was encoded using

小程序post请求

半城伤御伤魂 提交于 2019-11-29 04:37:33
小程序的post请求 https://developers.weixin.qq.com/miniprogram/dev/api/wx.request.html 这个请求头是必须的 POST请求 header: { 'content-type': 'application/x-www-form-urlencoded', }, data 参数说明 最终发送给服务器的数据是 String 类型,如果传入的 data 不是 String 类型,会被转换成 String 。转换规则如下: 对于 GET 方法的数据,会将数据转换成 query string(encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...) 对于 POST 方法且 header['content-type'] 为 application/json 的数据,会对数据进行 JSON 序列化 对于 POST 方法且 header['content-type'] 为 application/x-www-form-urlencoded 的数据,会将数据转换成 query string (encodeURIComponent(k)=encodeURIComponent(v)

javascript encodeURIComponent and converting spaces to + symbols

淺唱寂寞╮ 提交于 2019-11-29 03:19:40
I would like to encode my URL, but I want to convert spaces to plus symbols. This is what I attempted to do... var search = "Testing this here &"; encodeURIComponent(search.replace(/ /gi,"+")); The output from that is Testing%2Bthis%2Bhere%2B%26 but what I would like it to be is Testing+this+here+%26 I tried replacing the space with %20 to convert it into a plus symbol, but that didn't seem to work. Can anyone tell me what it is I'm doing wrong here? encodeURIComponent(search).replace(/%20/g, "+"); What you're doing wrong here is that first you convert spaces to pluses, but then

url-Encode vs Base64 encoding ( usages)?

时光怂恿深爱的人放手 提交于 2019-11-28 22:21:46
问题 I was wondering... (except the issue with the base64's plus'+' sign in query string - which is translated to 'space' and can be solved by %2b) :---> which is the preferred way to transfer data in query string? Both functions can be used through the JS commands: btoa encodeUriComponent so im asking myself(and you) : when should I use what ? ( ive always used encodeUriCompoonent - by instinct). the problem that the definitions are different - but the implementations can be similar... edit I

js原生实现base64编码解码(utf8字符集)

时光总嘲笑我的痴心妄想 提交于 2019-11-28 21:54:21
详细参考本篇博文 https://blog.csdn.net/qq_25243451/article/details/88658864 后台传来经过 base64 编码的字符串(原始字符串含有中文), 需要在前端进行解码, 但 js 中的 atob 解码方法不支持 unicode 字符集( btoa 也是), 换言之, 中文被解码出来是会乱码的。 网上流传的多是使用encodeURIComponent 和 decodeURIComponent,原理是对中文进行百分号编码,转换为%xxx这种样式,但是这样使用之后会使编码变长,如下 图1(期望的编码值) 图2(使用百分号编码之后) 同样的元字符,使用encodeURIComponent之后字符更长,原因是没有对百分号编码的字符的进行编码,导致编码后的字符串变长 因此在这里调用escape和unescape方法: const Base64 = { encode: (str) => { return window.btoa(unescape(encodeURIComponent(str))) }, decode: (str) => { return decodeURIComponent(escape(window.atob(str))) } } 具体的详解可以参考开头提到的那篇博文 来源: https://www.cnblogs.com

javascript encodeURIComponent and converting spaces to + symbols

孤者浪人 提交于 2019-11-27 17:28:56
问题 I would like to encode my URL, but I want to convert spaces to plus symbols. This is what I attempted to do... var search = "Testing this here &"; encodeURIComponent(search.replace(/ /gi,"+")); The output from that is Testing%2Bthis%2Bhere%2B%26 but what I would like it to be is Testing+this+here+%26 I tried replacing the space with %20 to convert it into a plus symbol, but that didn't seem to work. Can anyone tell me what it is I'm doing wrong here? 回答1: encodeURIComponent(search).replace(/

What is the equivalent of JavaScript's encodeURIcomponent in PHP?

情到浓时终转凉″ 提交于 2019-11-26 21:57:44
What is the equivalent of JavaScript's encodeURIcomponent function in PHP? Gumbo Try rawurlencode . Or to be more precise: function encodeURIComponent($str) { $revert = array('%21'=>'!', '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')'); return strtr(rawurlencode($str), $revert); } This function works exactly how encodeURIComponent is defined : encodeURIComponent escapes all characters except the following: alphabetic, decimal digits, - _ . ! ~ * ' ( ) Did you try urlencode ? function encodeURIComponent($string) { $result = ""; for ($i = 0; $i < strlen($string); $i++) { $result .=

基础术语理解

空扰寡人 提交于 2019-11-26 16:34:13
1JSON对象和JS对象的理解 格式: JSON对象里引号必须用双引号且key值必须用双引号! {"name":1} ,{"name":"李华"} //JSON对象 {name:"1"},{"name":'李华'} //JS对象 '{"name":"1","age":2}' //JSON字符串 JSON 即JS对象表示法.是JS的一种简单数据格式. 但仍独立于平台和语言.是一种轻量级文本数据交换格式,传输速度快.跨多平台 JS中处理JSON数据,不需要引入任何API或工具库 2.URL和URI的区别 URL:统一资源定位符 URI:统一资源标识符 URL是一个地址,URI是一个资源; 每个URL都是URI,但不是每个URI都是URL 可以简单理解 URL是URI的子类 3.encodeURI 、encodeURIComponent编码的区别与应用场景 enconde编码/ decode解码 为什么要使用编码? 统一各个终端对URL的编码方式. 这样后端接收的都是一样的 由于RFC 1738没有对URL编码指定具体规格,不同终端,可能对同一地址产生不同编码. 区别: encodeURI :URL地址编码,有些符号不能编码 encodeURIComponent:URL参数编码,都可以编码 使用: let querystr = encodeURIComponent(JSON