urlencode

How do I replace all the spaces with %20 in C#?

安稳与你 提交于 2019-11-26 18:47:00
I want to make a string into a URL using C#. There must be something in the .NET framework that should help, right? LiraNuna I believe you're looking for HttpServerUtility.UrlEncode . System.Web.HttpUtility.UrlEncode(string url) Another way of doing this is using Uri.EscapeUriString(stringToEscape) . Gilda I found useful System.Web.HttpUtility.UrlPathEncode(string str); It replaces spaces with %20 and not with +. To properly escape spaces as well as the rest of the special characters, use System.Uri.EscapeDataString(string stringToEscape) . As commented on the approved story, the

How do you UrlEncode without using System.Web?

℡╲_俬逩灬. 提交于 2019-11-26 18:05:27
I am trying to write a windows client application that calls a web site for data. To keep the install to a minimum I am trying only use dlls in the .NET Framework Client Profile . Trouble is that I need to UrlEncode some parameters, is there an easy way to do this without importing System.Web.dll which is not part of the Client Pofile? ToddBFisher System.Uri.EscapeUriString() can be problematic with certain characters, for me it was a number / pound '#' sign in the string. If that is an issue for you, try: System.Uri.EscapeDataString() //Works excellent with individual values Here is a SO

XHTML and & (Ampersand) encoding

我是研究僧i 提交于 2019-11-26 17:42:08
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 handle the URL correctly and ignore the y parameter. How can I make this link work and validate correctly? It

Prefilling gmail compose screen with HTML text

早过忘川 提交于 2019-11-26 17:39:35
问题 Hi guys I found out that in order to open a GMAIL compose screen you'd have to be logged in and open the following link: https://mail.google.com/a/domain/?view=cm&fs=1&tf=1&source=mailto&to=WHOEVER%40COMPANY.COM&su=SUBJECTHERE&cc=WHOEVER%40COMPANY.COM&bcc=WHOEVER%40COMPANY.COM&body=PREPOPULATEDBODY Replacing the variables fills in the corresponding places on the compose form. However if I want to enter into the body multiline text or line breaks its just not working even if I urlencode it.

Parse string to URL

百般思念 提交于 2019-11-26 16:36:06
问题 How can I parse dynamic string values in order to create URL instances? I need to replace spaces with %20 , accents, non-ASCII characters...? I tried to use URLEncoder but it also encodes / character and if I give a string encoded with URLEncoder to the URL constructor I get a MalformedURLException (no protocol). 回答1: URLEncoder has a very misleading name. It is according to the Javadocs used encode form parameters using MIME type application/x-www-form-urlencoded . With this said it can be

How do I encode URI parameter values?

穿精又带淫゛_ 提交于 2019-11-26 16:09:14
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 encoding a single value at a time so it has no way of knowing that value1 and value2 are part of the

Why is curl truncating this query string?

风格不统一 提交于 2019-11-26 15:56:51
问题 I'm sure the answer to this is going to be some painfully obvious character encoding issue... I'm using curl on the command line to test some endpoints in a python app. The endpoint takes url params of latitude and longitude. Nothing too special. I put in the command: curl -v -L http://localhost:5000/pulse/?lat=41.225&lon=-73.1 Server responds, with verbose curl output: * Connected to localhost (127.0.0.1) port 5000 (#0) > GET /pulse/?lat=41.225 HTTP/1.1 > User-Agent: curl/7.21.6 (i686-pc

Should I URL-encode POST data?

强颜欢笑 提交于 2019-11-26 15:46:27
I'm POSTing data to an external API (using PHP, if it's relevant). Should I URL-encode the POST variables that I pass? Or do I only need to URL-encode GET data? Thanks! UPDATE: This is my PHP, in case it is relevant: $fields = array( 'mediaupload'=>$file_field, 'username'=>urlencode($_POST["username"]), 'password'=>urlencode($_POST["password"]), 'latitude'=>urlencode($_POST["latitude"]), 'longitude'=>urlencode($_POST["longitude"]), 'datetime'=>urlencode($_POST["datetime"]), 'category'=>urlencode($_POST["category"]), 'metacategory'=>urlencode($_POST["metacategory"]), 'caption'=>($_POST[

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

核能气质少年 提交于 2019-11-26 15:20:23
This question already has an answer here: URL encoding the space character: + or %20? 4 answers 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? Form data (for GET or POST) is usually encoded as application/x-www-form-urlencoded : this specifies + for spaces. URLs are encoded as RFC 1738

Ruby url encoding string

百般思念 提交于 2019-11-26 15:08:59
问题 How do I URI::encode a string like: \x12\x34\x56\x78\x9a\xbc\xde\xf1\x23\x45\x67\x89\xab\xcd\xef\x12\x34\x56\x78\x9a To get it in a format like: %124Vx%9A%BC%DE%F1%23Eg%89%AB%CD%EF%124Vx%9A (as per RFC 1738) Here's what I've tried: irb(main):123:0> URI::encode "\x12\x34\x56\x78\x9a\xbc\xde\xf1\x23\x45\x67\x89\xab\xcd\xef\x12\x34\x56\x78\x9a" ArgumentError: invalid byte sequence in UTF-8 from /usr/local/lib/ruby/1.9.1/uri/common.rb:219:in `gsub' from /usr/local/lib/ruby/1.9.1/uri/common.rb:219