urlencode

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

大城市里の小女人 提交于 2019-11-29 13:43:37
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 %A0 indicates a NBSP (U+00A0). + indicates a normal space (U+0020). The NBSP displays as a replacement character (U+FFFD) because the encoding of the

URL component encoding in Node.js

℡╲_俬逩灬. 提交于 2019-11-29 11:26:38
问题 I want to send http request using node.js. I do: http = require('http'); var options = { host: 'www.mainsms.ru', path: '/api/mainsms/message/send?project='+project+'&sender='+sender+'&message='+message+'&recipients='+from+'&sign='+sign }; http.get(options, function(res) { console.log('STATUS: ' + res.statusCode); console.log('HEADERS: ' + JSON.stringify(res.headers)); }).on('error', function(e) { console.log('ERROR: ' + e.message); }); When my path like this: /api/mainsms/message/send?project

Urlencode and file_get_contents

冷暖自知 提交于 2019-11-29 10:28:47
We have an url like http://site.s3.amazonaws.com/images/some image @name.jpg inside $string What I'm trying to do (yes, there is a whitespace around the url): $string = urlencode(trim($string)); $string_data = file_get_contents($string); What I get (@ is also replaced): file_get_contents(http%3A%2F%2Fsite.s3.amazonaws.com%2Fimages%2Fsome+image+@name.jpg)[function.file-get-contents]: failed to open stream: No such file or directory If you copy/paste http://site.s3.amazonaws.com/images/some image @name.jpg into browser address bar, image will open. What's bad and how to fix that? The URL you

php - file_get_contents - Downloading files with spaces in the filename not working

心不动则不痛 提交于 2019-11-29 07:02:57
I am trying to download files using file_get_contents() function. However if the location of the file is http://www.example.com/some name.jpg , the function fails to download this. But if the URL is given as http://www.example.com/some%20name.jpg , the same gets downloaded. I tried rawurlencode() but this coverts all the characters in the URL and the download fails again. Can someone please suggest a solution for this? I think this will work for you: function file_url($url){ $parts = parse_url($url); $path_parts = array_map('rawurldecode', explode('/', $parts['path'])); return $parts['scheme']

Why doesn't decodeURI(“a+b”) == “a b”?

房东的猫 提交于 2019-11-29 06:35:36
问题 I'm trying to encode URLs in Ruby and decode them with Javascript. However, the plus character is giving me weird behavior. In Ruby: [Dev]> CGI.escape "a b" => "a+b" [Dev]> CGI.unescape "a+b" => "a b" So far so good. But what about Javascript? >>> encodeURI("a b") "a%20b" >>> decodeURI("a+b") "a+b" Basically I need a method of encoding / decoding URLs that works the same way in Javascript and Ruby. Edit: decodeURIComponent is no better: >>> encodeURIComponent("a b") "a%20b" >>>

how to encode href attribute in HTML

不羁的心 提交于 2019-11-29 05:51:14
What should be done against contents of href attribute: HTML or URL encoding? <a href="???">link text</a> On the one hand, since href attribute contains URL I should use URL encoding. On the other hand, I'm inserting this URL into HTML, so it must be HTML encoded. Please help me to overcome this contradiction. Thanks. EDIT: Here's the contradiction. Suppose there might be the '<' and '>' characters in the URL. URL encoding won't escape them, so there will be reserved HTML characters inside the href attribute, which violates the standard. HTML encoding will escape '<' and '>' characters and

Best way to get query string from a URL in python?

橙三吉。 提交于 2019-11-29 04:56:18
问题 I need to get the query string from this URL https://stackoverflow.com/questions/ask?next=1&value=3 and I don't want to use request.META. I have figured out that there are two more ways to get the query string: Using urlparse urlparse.urlparse(url).query Using url encode Use urlencode and pass the request.GET params dictionary into it to get the string representation. So which way is better? My colleagues prefer urlencode but have not provided a satisfying explanation. They claim that

C# web request with POST encoding question

北城以北 提交于 2019-11-29 04:12:06
On the MSDN site there is an example of some C# code that shows how to make a web request with POST'ed data. Here is an excerpt of that code: WebRequest request = WebRequest.Create ("http://www.contoso.com/PostAccepter.aspx "); request.Method = "POST"; string postData = "This is a test that posts this string to a Web server."; byte[] byteArray = Encoding.UTF8.GetBytes (postData); // (*) request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = byteArray.Length; Stream dataStream = request.GetRequestStream (); dataStream.Write (byteArray, 0, byteArray.Length);

Encode the url including hyphen(-) and dot(.) in php

安稳与你 提交于 2019-11-29 03:46:15
I need the encoded URL for processing in one of the API, but it requires the full encoded URL. For example, the URL from: http://test.site-raj.co/999999?lpp=1&px2=IjN has to become an encoded URL, like: http%3a%2f%test%site%2draj%2eco%2f999999%3flpp%3d1%26px2%3dIjN I need every symbol to be encoded, even the dot(.) and hyphen(-) like above. Try this. Inside a function maybe if you are using it more than once... $str = 'http://test.site.co/999999?lpp=1&p---x2=IjN'; $str = urlencode($str); $str = str_replace('.', '%2E', $str); $str = str_replace('-', '%2D', $str); echo $str; This will encode all

How to URL encode periods?

為{幸葍}努か 提交于 2019-11-29 02:58:23
I need to URL encode some periods since I have to pass some document path along and it is like this http://example.com/test.aspx?document=test.docx So test.docx is causing me an error of an illegal character. So I need to change it to . --> %2E I tried to use Server.UrlEncode string b = Server.UrlEncode("http://example.com/test.aspx?document=test.docx"); but I get "http%3a%2f%2fexample.com%2ftest.aspx%3fdocument%3dtest.docx" So do I have to use like a string replace and do it manually and replace all periods with that code? The period there isn't he problem (given that %2E doesn't solve the