urlencode

Python urllib简单使用

旧时模样 提交于 2019-12-20 18:08:05
Python的urllib和urllib2模块都做与请求URL相关的操作。 它们最显著的差异为: urllib2可以接受一个Request对象,并以此可以来设置一个URL的headers,但是urllib只接收一个URL。 urllib模块可以提供进行urlencode的方法,该方法用于GET查询字符串的生成,urllib2的不具有这样的功能. python 2.7.x提供了urllib与urllib2,鉴于上述异同两个库通常搭配使用。 urlopen urllib2.urlopen(url, *data, *timeout) urlopen方法是urllib2模块最常用的方法,用于访问发送某一请求。 url参数可以是一个字符串url或者是一个Request对象。 可选参数timeout用于设置超时时间,以秒为单位。 如果没有指定,将使用设置的全局默认timeout值。 urlopen使用默认opener进行访问, 为阻塞式IO. 如果请求成功,函数将返回响应。 在data为None时默认用GET方法: import urllib2 response = urllib2.urlopen('http://python.org/') html = response.read() print(html) 使用POST发送参数前需要先将参数编码: import urllib import

Do colons require encoding in URI query parameters?

我的梦境 提交于 2019-12-20 17:34:10
问题 I've noticed that Java's UriBuilder isn't encoding the : characters included in my query parameter values (ISO 8601-formatted strings). According to Wikipedia, it seems colon should be encoded. In particular, encoding the query string uses the following rules: Letters (A-Z and a-z), numbers (0-9) and the characters '.','-','~' and '_' are left as-is SPACE is encoded as '+' or %20[citation needed] All other characters are encoded as %FF hex representation with any non-ASCII characters first

how do I encode a complete http url String correctly?

坚强是说给别人听的谎言 提交于 2019-12-20 02:32:19
问题 I get a url string from a user and would like to transform it to a legal http url: " http://one.two/three?four five " should turn into " http://one.two/three?four%20five " however, URLEncoder does not help, as it encodes the entire string (including the legal "://"). help? 回答1: With external library: import org.apache.commons.httpclient.util.URIUtil; String myUrl_1= "http://one.two/three?four five"; System.out.println(URIUtil.encodeQuery(myUrl_1)); And the output: http://one.two/three?four

How to get a querystring when it is URLEncoded or has percent characters in ASP.NET

霸气de小男生 提交于 2019-12-19 10:32:26
问题 How to get the actual querystring from the Request object when the querystring is UrlEncoded or has percent characters in ASP.NET? Basicly, if I have a Url like this: Default.aspx?p=%b4 , how do I get a string populated with "%b4"? Request.QueryString["p"] returns a non printable character. Request.RawUrl returns Default.aspx?p=%ufffd" Request.Url.AbsoluteUri returns Default.aspx?p=%EF%BF%BD How can I get "%b4" back? 回答1: I dug into this further, and believe I know what's causing this: an

How to get a querystring when it is URLEncoded or has percent characters in ASP.NET

旧街凉风 提交于 2019-12-19 10:32:09
问题 How to get the actual querystring from the Request object when the querystring is UrlEncoded or has percent characters in ASP.NET? Basicly, if I have a Url like this: Default.aspx?p=%b4 , how do I get a string populated with "%b4"? Request.QueryString["p"] returns a non printable character. Request.RawUrl returns Default.aspx?p=%ufffd" Request.Url.AbsoluteUri returns Default.aspx?p=%EF%BF%BD How can I get "%b4" back? 回答1: I dug into this further, and believe I know what's causing this: an

how can I javascript decodeURI in PHP?

寵の児 提交于 2019-12-19 03:18:49
问题 I have a javascript which sends some specific information to a PHP api . Before to send it performs encodeURI . How can I "decode" it in PHP ? I understand that urldecode/urlencode is different that javascript encode/decodeURI so what can I use ? 回答1: Unless you've encoded it multiple times (e.g. by explicitly calling the encode method AND inserting the value into a form field which is then submitted) you don't need to do anything - it is transparently converted back to its original form when

how can I javascript decodeURI in PHP?

别来无恙 提交于 2019-12-19 03:18:34
问题 I have a javascript which sends some specific information to a PHP api . Before to send it performs encodeURI . How can I "decode" it in PHP ? I understand that urldecode/urlencode is different that javascript encode/decodeURI so what can I use ? 回答1: Unless you've encoded it multiple times (e.g. by explicitly calling the encode method AND inserting the value into a form field which is then submitted) you don't need to do anything - it is transparently converted back to its original form when

Why is the comma URL encoded?

亡梦爱人 提交于 2019-12-18 12:52:54
问题 When debugging in ASP.NET MVC, I don't see a difference between: http://mysite.com?q=hi,bye and http://mysite.com?q=hi%2Cbye The querystring param "q" always has a value of "hi,bye". So why is the comma encoded? I want to do something like this https://stackoverflow.com/a/752109/173957. I have this form: <form method="GET" action="/Search"> <input type="hidden" name="q" value="hi,bye"/> <input type="submit" value="ok"/> </form> How can I prevent this value from being encoded? 回答1: The URI

Python urllib urlencode problem with æøå

人盡茶涼 提交于 2019-12-18 12:37:54
问题 How can I urlencode a string with special chars æøå? ex. urllib.urlencode('http://www.test.com/q=testæøå') I get this error :(.. not a valid non-string sequence or mapping object 回答1: You should pass dictionary to urlencode, not a string. See the correct example below: from urllib import urlencode print 'http://www.test.com/?' + urlencode({'q': 'testæøå'}) 回答2: urlencode is intended to take a dictionary, for example: >>> q= u'\xe6\xf8\xe5' # u'æøå' >>> params= {'q': q.encode('utf-8')} >>>

Difference between “+” and “%A0” - urlencoding?

有些话、适合烂在心里 提交于 2019-12-18 05:53:12
问题 I am url encoding a string of text to pass along to a function. However, it encodes the second space in a double-space as "%A0". This means that when I decode the string, the "%A0" is displayed as a question mark in a black box. I really just need to be able to remove the extra space, but I'd like to understand what is causing this and how to handle it correctly. For example: Something Something else Encodes to: Something+%A0Something+else 回答1: %A0 indicates a NBSP (U+00A0). + indicates a