How to turn string into readable by php server way? (C#) - c#

I know that my server on real form submit turns %CE%EB%E5%E3+%DF%EA%F3%F8%EA%E8%ED into Олег Якушкин . How to peform string transfer from Олег Якушкин into %CE%EB%E5%E3+%DF%EA%F3%F8%EA%E8%ED using C#?

Like this:
Uri.EscapeDataString(str)
Note that this will encode a space character as %20, not +. However, PHP should handle that fine.

HttpUtility.UrlEncode

Related

URL Decoder c# asp.net

In a QueryString I have a part that looks like this
...u4w51EEcg8%2bj04e7C....
When I am using HttpUtility.UrlDecode the part "%2b" which represents a "+" just turns into a white space.
I'm using HttpUtility.UrlEncode in the first place to encode the string.
Does anyone have any clue to what is going on?
Are you decoding twice? For convenience, a + sign in a URL decodes to (space, 0x20). While %2b should decode to +, decoding that will give you .
EDIT: Just saw your self-answer, and yeah, always check whether your getter functions / properties automatically decode for you. Double-decoding usually doesn't produce the desired result, and can even lead to security risks.
It looks like that "Request.QueryString[]" decodewhatever it gets, so what happened was that I decode the QueryString 2 times, which makes "+" a whitespace.

How to convert a string to a url encoded

I want to be able to convert for example ™ to %99 but i dont know what encoding is that
I tried looking at httputility class but i dont get %99 i get other wierd signs can you please help me? thanks
Im using C#
I want to do that so my the login would work with all chars like ™ im using http post method for a vb forum i need first to correct the encoding
EDIT : Not sure but can i just change the Content-Type : application/x-www-form-urlencoded
to something that accepts signs like trademark so it would work?
From the subject it seems that you are trying to encode given string to url string, e.g. changing something like user#email.com to user%40email.com so it can be in a url http://www.example.com?email=user%40gmail.com
Can you provide a little more information?
If you are trying to pass the string through a URL, than I highly recommend the HttpUtility.UrlEncode method to be on the safe side.

how to encode apostrophes for a webpage

i am using the cluetip plugin and the simple use case is to to put the content in a title attribute, like below:
<a title='Top title|detail content'>Text</a>
i am now running into issues where the string that is inside "detail content' has an apostrophe inside of it and it seems to confuse cluetip plugin. Is there anyway to escape or encode an apostrophe to allow cluetip to work properly.
You're looking for &apos;.
See HTML entities.
You'll want to use ' per this link since &apos; has flaky browser support. See this old post for more info.
have you tried HTML escaping the apostrophe?

Url encoded characters, ViewState and byte[] arrays oh my

I am trying to throw together a screen scraper and keep getting invalid viewstate issues. It appears that during the System.Net.WebClient download of data or the System.Text.UTF8Encoding.Default.GetString call to convert the byte array returned by the WebClient DownloadData call to a string - that strings which match url character codes are being converted.
ie
Url encoded characters strings like %2B are being converted to their normal characters (+ for %2B).
Is this happening in the WebClient class? Is it the way I am converting the byte array to a string?
EDIT:
Based on suggestions I tried changing to the DownloadString call from the WebClient class and the resulting string has converted the character codes to the specific character so it appears WebClient is the culprit.
EDIT 2:
Solved. By making a call to System.Web.HttpUtility.UrlEncode I was able to convert the + back to %2B before sending the viewstate string back up to the server in subsequent requests. I am still at a loss as to where and why the problem was occurring but the server was expecting a viewstate string that contained ...%2B... and was getting ...+... and determining the viewstate to be invalid and throwing the exception. Kudos to Jon & Henk for forcing me to rethink my assumptions.
If you use System.Text.UTF8Encoding.Default then you're not using UTF-8 - you're using the default encoding for the system. It's equivalent to Encoding.Default, but in a more confusing form. Use Encoding.UTF8 to get a UTF-8 encoding... or use WebClient.DownloadString as Henk suggested.
On the other hand, it's not clear what you're trying to download. If you're trying to download geuinely binary data then you shouldn't be trying to convert it to a string at all.
It would help if you would clarify you question - try to provide a lot more context about what's making the requests, what's having problems, etc.
And what happened if you just use WebClient.DownloadString() instead of opening a binary stream?

ASP.NET MVC -- How to Format URL Query String

How to I format a query string so it looks like this
search?q=power+tools
currently it looks like this
search?q=power%20tools
Is there a way to do this without replacing the space for a plus sign?
HttpServerUtility.UrlDecode
In a ASP.NET page HttpServerUtility instance can be accessed by Page.Server property.
Not really. HttpUtility.UrlEncode encodes it that way, and that is what is used by pretty much everything in ASP.NET.
Besides, from memory %20 is actually correct for query strings, and + is correct for URLs. Ignore this, it's incorrect.

Categories

Resources