urlencode

Java equivalent of Pythons urllib.urlencode(HashMap based UrlEncode)

荒凉一梦 提交于 2019-12-04 12:43:52
From Whats the java equivalent of Python’s urllib.urlencode? Like >>> urllib.urlencode({'abc':'d f', 'def': '-!2'}) 'abc=d+f&def=-%212' Where I can pass a HashMap of key values and it encodes and gives me the url string .. Edit: I wanted to avoid this scenario String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8"); data += "&" + URLEncoder.encode("key2", "UTF-8") + "=" + URLEncoder.encode("value2", "UTF-8"); of manually concatenating the strings with = and & java.net.URLEncoder should work for you - though you would have to extend it to accept the hashmap

python3 requests use quote instead of quote_plus

可紊 提交于 2019-12-04 12:34:06
问题 I use Python 3 and the requests module/library for querying a REST service. It seems that requests by default uses urllib.parse.quote_plus() for urlencoding, i.e. spaces are converted to + . However the REST service I query misinterpretes this as and . So I need to encode spaces as %20 , i.e. use urllib.parse.quote() instead. Is there an easy way to do this with requests? I couldn't find any option in the documentation. 回答1: It turns out you can! from requests.utils import requote_uri url =

Library to convert JSON to urlencoded

不打扰是莪最后的温柔 提交于 2019-12-04 11:17:13
问题 We are doing some integration towards a quite inconsistent (Zurmo-)REST API. The API only accepts urlencoded strings as its payload in the http posts, but it answers with JSON. So as the documentation was very unclear on this we naturally thought we could post JSON to it, but this was not the case. So now we have all our code generating JSON when we need to send it as x-www-form-urlencoded, is there any java library that can do a conversion from JSON to an urlencoded string? We are currently

Encode an URL with Play 2

为君一笑 提交于 2019-12-04 10:32:03
问题 How can I encode an URL in a template with Play 2? I search a helper like this: <a href="@urlEncode(name)">urlEncode doesn't work now</a> I have found a pull request, but this doesn't seem to work with the actual play 2.0.3 release. 回答1: As of 2.1 you can use @helper.urlEncode <a href="@helper.urlEncode(foo)">my href is urlencoded</a> 回答2: As I can see in linked ticked it will be resolved in Play 2.1 Quickest solution is placing ,method(s) for that in you controller ( Application.java in this

How can I send a GET request containing a colon, to an ASP.NET MVC2 controller?

倾然丶 夕夏残阳落幕 提交于 2019-12-04 10:18:20
This works fine: GET /mvc/Movies/TitleIncludes/Lara%20Croft When I submit a request that contains a colon, like this: GET /mvc/Movies/TitleIncludes/Lara%20Croft:%20Tomb ...it generates a 400 error. The error says ASP.NET detected invalid characters in the URL. If I try url-escaping, the request looks like this: GET /mvc/Movies/TitleIncludes/Lara%20Croft%3A%20Tomb ...and this also gives me a 400 error. If I replace the colon with a | : GET /mvc/Movies/TitleIncludes/Lara%20Croft|%20Tomb ..that was also rejeted as illegal, this time with a 500 error. The message: Illegal characters in path. URL

A potentially dangerous Request.Path value was detected from the client (?) with valid URL

断了今生、忘了曾经 提交于 2019-12-04 08:44:31
I have an ASP.NET MVC 4 Web Application running on IIS 7.5 for a few weeks now and I noticed that just recently I have been getting quite a lot of the following errors: System.Web.HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (?). at System.Web.HttpRequest.ValidateInputIfRequiredByConfig() at System.Web.HttpApplication.PipelineStepManager.ValidateHelper(HttpContext context) I know that this exception is caused when the URL path contains illegal characters but the strange thing is that in my case the URL is valid. Here is one example of the

Why is System.Web.HttpUtility.UrlEncode giving namespace name doesn't exist in Visual C# 2008?

荒凉一梦 提交于 2019-12-04 08:11:14
问题 I'm trying to encode a URL using the HttpUtility.UrlEncode() method, why am I getting The type or namespace name 'HttpUtility' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) error ? I'm using Visual C# 2008, Express Edition. The code I'm using is simplistic: using System; using System.Text; using System.Windows.Forms; using System.Net; using System.IO; using System.Web; namespace Lincr { public partial class frmMain : Form { public frmMain() {

Transformer library that comes with Java converts spaces in file paths to %20

大兔子大兔子 提交于 2019-12-04 07:22:08
Here is a test application that writes out XML Files. Why are the spaces in my path being converted to %20 ? public class XmlTest { public static void main(String[] args) { String filename = "C:\\New Folder\\test.xml"; try { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document doc = docBuilder.newDocument(); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes");

Strange url encoding issue

半世苍凉 提交于 2019-12-04 06:13:54
I have a strange issue with urlencoding a plus sign + as a query param for a request against an API. The API's documentation states: The date has to be in the W3C format, e.g. '2016-10-24T13:33:23+02:00'. So far so good, so I'm using this code (minimalized) to generate the url, using Spring's UriComponentBuilder: DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssX"); ZonedDateTime dateTime = ZonedDateTime.now().minusDays(1); String formated = dateTime.format(formatter); UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(baseUrl);

python中的urlencode与urldecode

两盒软妹~` 提交于 2019-12-04 05:48:29
当url地址含有中文,或者参数有中文的时候,这个算是很正常了,但是把这样的url作为参数传递的时候(最常见的callback),需要把一些中文甚至'/'做一下编码转换。 一、urlencode urllib库里面有个urlencode函数,可以把key-value这样的键值对转换成我们想要的格式,返回的是a=1&b=2这样的字符串,比如: >>> from urllib import urlencode >>> data = { ... 'a': 'test', ... 'name': '魔兽' ... } >>> print urlencode(data) a=test&name=%C4%A7%CA%DE 如果只想对一个字符串进行urlencode转换,怎么办?urllib提供另外一个函数:quote() >>> from urllib import quote >>> quote('魔兽') '%C4%A7%CA%DE' 二、urldecode 当urlencode之后的字符串传递过来之后,接受完毕就要解码了——urldecode。urllib提供了unquote()这个函数,可没有urldecode()! >>> from urllib import unquote >>> unquote('%C4%A7%CA%DE') '\xc4\xa7\xca\xde' >>>