urlencode

URL Encode and Decode Special character in Java

蓝咒 提交于 2019-11-29 02:57:05
问题 In Java, I need to use HTTP Post to send request to server, but if in the parameter of the URL contains some special character it throws below Exception java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "&'" The code to send data DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(URL); String sessionId = RequestUtil.getRequest().getSession().getId(); String data = arg.getData().toString();

urllib.quote() throws KeyError

纵然是瞬间 提交于 2019-11-28 22:04:21
问题 To encode the URI, I used urllib.quote("schönefeld") but when some non-ascii characters exists in string, it thorws KeyError: u'\xe9' Code: return ''.join(map(quoter, s)) My input strings are köln, brønshøj, schönefeld etc. When I tried just printing statements in windows(Using python2.7, pyscripter IDE). But in linux it raises exception (I guess platform doesn't matter). This is what I am trying: from commands import getstatusoutput queryParams = "schönefeld"; cmdString = "http://baseurl" +

how to insert %20 in place of space in android

主宰稳场 提交于 2019-11-28 21:07:35
I have a xml URL file in which there are white spaces i want to replace white spaces with %20.. how to do this???? SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); /** Send URL to parse XML Tags */ URL sourceUrl = new URL( "http://www.arteonline.mobi/iphone/output.php?gallery=MALBA%20-%20MUSEO%20DE%20ARTE%20LATINOAMERICANO%20DE%20BUENOS%20AIRES"); XMLHandlerartistspace myXMLHandler = new XMLHandlerartistspace(); xr.setContentHandler(myXMLHandler); xr.parse(new InputSource(sourceUrl.openStream())); Sumant Try this:

urlencode a multidimensional dictionary in python

妖精的绣舞 提交于 2019-11-28 20:55:18
How can I get a URL-encoded version of a multidimensional dictionary in Python? Unfortunately, urllib.urlencode() only works in a single dimension. I would need a version capable of recursively encoding the dictionary. For example, if I have the following dictionary: {'a': 'b', 'c': {'d': 'e'}} I want to obtain the following string: a=b&c[d]=e OK people. I implemented it myself: import urllib def recursive_urlencode(d): """URL-encode a multidimensional dictionary. >>> data = {'a': 'b&c', 'd': {'e': {'f&g': 'h*i'}}, 'j': 'k'} >>> recursive_urlencode(data) u'a=b%26c&j=k&d[e][f%26g]=h%2Ai' """

Url encoding quotes and spaces

白昼怎懂夜的黑 提交于 2019-11-28 18:59:08
问题 I have some query text that is being encoded with JavaScript, but I've encountered a use case where I might have to encode the same text on the server side, and the encoding that's happening is not the same. I need it to be the same. Here's an example. I enter "I like food" into the search box and hit the search button. JavaScript encodes this as %22I%20like%20food%22 Let's say I get the same value as a string on a request object on the server side. It will look like this: "\"I like food\""

urlencode()

混江龙づ霸主 提交于 2019-11-28 18:18:09
1、作用 将QueryDict->浏览器url的参数 def index(request): ret = request.GET print("GET", ret) # GET <QueryDict: {'name': ['wt'], 'age': ['23'], 'gender': ['male']}> ret = ret.urlencode() print("new", ret) # new name=wt&age=23&gender=male return HttpResponse("ok") 来源: https://www.cnblogs.com/wt7018/p/11419236.html

URL/HTML Escaping/Encoding

 ̄綄美尐妖づ 提交于 2019-11-28 17:45:30
问题 I have always been confused with URL/HTML Encoding/Escaping. I am using PHP, so want to clear somethings up. Can I say that I should always use urlencode : for individual query string parts $url = 'http://test.com?param1=' . urlencode('some data') . '&param2=' . urlencode('something else'); htmlentities : for escaping special characters like <> so that if will be rendered properly by the browser Would there be any other places I might use each function. I am not good at all these escaping

Java URL encoding: URLEncoder vs. URI

人盡茶涼 提交于 2019-11-28 16:54:07
Looking on the W3 Schools URL encoding webpage , it says that @ should be encoded as %40 , and that space should be encoded as %20 . I've tried both URLEncoder and URI , but neither does the above properly: import java.net.URI; import java.net.URLEncoder; public class Test { public static void main(String[] args) throws Exception { // Prints me%40home.com (CORRECT) System.out.println(URLEncoder.encode("me@home.com", "UTF-8")); // Prints Email+Address (WRONG: Should be Email%20Address) System.out.println(URLEncoder.encode("Email Address", "UTF-8")); // http://www.home.com/test?Email%20Address

urllib.urlencode doesn't like unicode values: how about this workaround?

╄→гoц情女王★ 提交于 2019-11-28 16:19:51
If I have an object like: d = {'a':1, 'en': 'hello'} ...then I can pass it to urllib.urlencode , no problem: percent_escaped = urlencode(d) print percent_escaped But if I try to pass an object with a value of type unicode , game over: d2 = {'a':1, 'en': 'hello', 'pt': u'olá'} percent_escaped = urlencode(d2) print percent_escaped # This fails with a UnicodeEncodingError So my question is about a reliable way to prepare an object to be passed to urlencode . I came up with this function where I simply iterate through the object and encode values of type string or unicode: def encode_object(object

url encode behaving differently in Firefox and Internet Explorer

穿精又带淫゛_ 提交于 2019-11-28 14:32:06
I want to send a user's entry to google's geocode API. In doing so, I detected a problem. When I send the user input (e.g. "köln+Germany") through my script to the api in Firefox it works great. In Internet Explorer however it's not working. Here's the exempt of my code that's enough to show the problem: header('Content-type: text/html; charset=UTF-8'); header('Cache-Control: no-cache, must-revalidate'); $loc = urlencode($_GET['loc']); echo $address = "http://maps.googleapis.com/maps/api/geocode/json?address=$loc&sensor=false"; The output ($address) in Firefox is: http://maps.googleapis.com