urlencode

How do I encode URI parameter values?

孤者浪人 提交于 2019-11-26 06:02:28
问题 I want to send a URI as the value of a query/matrix parameter. Before I can append it to an existing URI, I need to encode it according to RFC 2396. For example, given the input: http://google.com/resource?key=value1 & value2 I expect the output: http%3a%2f%2fgoogle.com%2fresource%3fkey%3dvalue1%2520%26%2520value2 Neither java.net.URLEncoder nor java.net.URI will generate the right output. URLEncoder is meant for HTML form encoding which is not the same as RFC 2396. URI has no mechanism for

XHTML and & (Ampersand) encoding

◇◆丶佛笑我妖孽 提交于 2019-11-26 05:34:44
问题 My website is XHTML Transitional compliant except for one thing : the & (ampersand) in the URL are written as it is, instead of & That is, all the urls in my pages are usually like this: <a href=\"http://www.foo.com/page.aspx?x=1&y=2\">Foo</a> But XHTML validator generates this error: cannot generate system identifier for general entity \"y\" ... and it wants the url to be written like this: <a href=\"http://www.foo.com/page.aspx?x=1&y=2\">Foo</a> The problem is that IE and Firefox don\'t

How to properly URL encode a string in PHP?

▼魔方 西西 提交于 2019-11-26 05:28:47
问题 I\'m making a search page, where you type a search query and the form is submitted to search.php?query=your query . What PHP function is the best and that I should use for encoding/decoding the search query? 回答1: For the URI query use urlencode/urldecode; for anything else use rawurlencode/rawurldecode. The difference between urlencode and rawurlencode is that urlencode encodes according to application/x-www-form-urlencoded (space is encoded with + ) while rawurlencode encodes according to

In a URL, should spaces be encoded using %20 or +? [duplicate]

♀尐吖头ヾ 提交于 2019-11-26 04:21:33
问题 This question already has answers here : URL encoding the space character: + or %20? (4 answers) Closed 3 years ago . In a URL, should I encode the spaces using %20 or + ? For example, in the following example, which one is correct? www.mydomain.com?type=xbox%20360 www.mydomain.com?type=xbox+360 Our company is leaning to the former, but using the Java method URLEncoder.encode(String, String) with \"xbox 360\" (and \"UTF-8\" ) returns the latter. So, what\'s the difference? 回答1: Form data (for

How to generate url encoded anchor links with AngularJS?

℡╲_俬逩灬. 提交于 2019-11-26 04:21:18
问题 <a href=\"#/search?query={{address}}\" ng-repeat=\"address in addresses\"> {{address}} </a> generates links that are not url encoded if I understand correctly. What is the proper way to encode #/search?query={{address}} ? Example address is 1260 6th Ave, New York, NY . 回答1: You can use the native encodeURIComponent in javascript. Also, you can make it into a string filter to utilize it. Here is the example of making escape filter. js: var app = angular.module('app', []); app.filter('escape',

How to create query parameters in Javascript?

十年热恋 提交于 2019-11-26 03:51:45
问题 Is there any way to create the query parameters for doing a GET request in JavaScript? Just like in Python you have urllib.urlencode(), which takes in a dictionary (or list of two tuples) and creates a string like \'var1=value1&var2=value2\' . 回答1: Here you go: function encodeQueryData(data) { const ret = []; for (let d in data) ret.push(encodeURIComponent(d) + '=' + encodeURIComponent(data[d])); return ret.join('&'); } Usage: const data = { 'first name': 'George', 'last name': 'Jetson', 'age

JavaScript URL Decode function

心已入冬 提交于 2019-11-26 03:44:01
What's the best JavaScript URL decode utility? Encoding would be nice too and working well with jQuery is an added bonus. Geoff I've used encodeURIComponent() and decodeURIComponent() too. anshuman Here is a complete function (taken from PHPJS ): function urldecode(str) { return decodeURIComponent((str+'').replace(/\+/g, '%20')); } decodeURIComponent(mystring); you can get passed parameters by using this bit of code: //parse URL to get values: var i = getUrlVars()["i"]; function getUrlVars() { var vars = [], hash; var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1)

URLEncoder not able to translate space character

↘锁芯ラ 提交于 2019-11-26 03:24:37
问题 I am expecting System.out.println(java.net.URLEncoder.encode(\"Hello World\", \"UTF-8\")); to output: Hello%20World (20 is ASCII Hex code for space) However, what I get is: Hello+World Am I using the wrong method? What is the correct method I should be using? 回答1: This behaves as expected. The URLEncoder implements the HTML Specifications for how to encode URLs in HTML forms. From the javadocs: This class contains static methods for converting a String to the application/x-www-form-urlencoded

How to encode a URL in Swift

我是研究僧i 提交于 2019-11-26 03:07:03
问题 This is my URL . The problem is, that the address field is not being appended to urlpath . Does anyone know why that is? var address:string address = \"American Tourister, Abids Road, Bogulkunta, Hyderabad, Andhra Pradesh, India\" let urlpath = NSString(format: \"http://maps.googleapis.com/maps/api/geocode/json?address=\"+\"\\(address)\") 回答1: Swift 4.2 var urlString = originalString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) Swift 3.0 var address = "American Tourister,

Encoding URL query parameters in Java

前提是你 提交于 2019-11-26 02:54:04
问题 How does one encode query parameters to go on a url in Java? I know, this seems like an obvious and already asked question. There are two subtleties I\'m not sure of: Should spaces be encoded on the url as \"+\" or as \"%20\"? In chrome if I type in \"http://google.com/foo=?bar me\" chrome changes it to be encoded with %20 Is it necessary/correct to encode colons \":\" as %3B? Chrome doesn\'t. Notes: java.net.URLEncoder.encode doesn\'t seem to work, it seems to be for encoding data to be form