0

I have a textbox in my application, and the text from the textbox is sent as post data via a POST request. If I include any signs within the text such as £ or $ it converts them to question marks.

Is there any encoding I need to do to stop this from happening

Edit I do not have access to the server on the other end.

James Jeffery
  • 557
  • 2
  • 6
  • 14

4 Answers4

1

I've been experimenting with the various methods .NET provide for URL encoding. Perhaps the following table will be useful :

Unencoded UrlEncoded UrlEncodedUnicode UrlPathEncoded EscapedDataString EscapedUriString HtmlEncode HtmlAttributeEncode HexEscape
A         A          A                 A              A                 A                A          A                   %41
B         B          B                 B              B                 B                B          B                   %42
C         C          C                 C              C                 C                C          C                   %43
D         D          D                 D              D                 D                D          D                   %44

a         a          a                 a              a                 a                a          a                   %61
b         b          b                 b              b                 b                b          b                   %62
c         c          c                 c              c                 c                c          c                   %63
d         d          d                 d              d                 d                d          d                   %64

0         0          0                 0              0                 0                0          0                   %30
1         1          1                 1              1                 1                1          1                   %31
2         2          2                 2              2                 2                2          2                   %32
3         3          3                 3              3                 3                3          3                   %33

[space]   +          +                 %20            %20               %20              [space]    [space]             %20
!         !          !                 !              !                 !                !          !                   %21
"         %22        %22               "              %22               %22              "     "              %22
#         %23        %23               #              %23               #                #          #                   %23
$         %24        %24               $              %24               $                $          $                   %24
%         %25        %25               %              %25               %25              %          %                   %25
&         %26        %26               &              %26               &                &      &               %26
'         %27        %27               '              '                 '                '      '               %27
(         (          (                 (              (                 (                (          (                   %28
)         )          )                 )              )                 )                )          )                   %29
*         *          *                 *              *                 *                *          *                   %2A
+         %2b        %2b               +              %2B               +                +          +                   %2B
,         %2c        %2c               ,              %2C               ,                ,          ,                   %2C
-         -          -                 -              -                 -                -          -                   %2D
.         .          .                 .              .                 .                .          .                   %2E
/         %2f        %2f               /              %2F               /                /          /                   %2F
:         %3a        %3a               :              %3A               :                :          :                   %3A
;         %3b        %3b               ;              %3B               ;                ;          ;                   %3B
<         %3c        %3c               <              %3C               %3C              &lt;       &lt;                %3C
>         %3e        %3e               >              %3E               %3E              &gt;       >                   %3E
=         %3d        %3d               =              %3D               =                =          =                   %3D
?         %3f        %3f               ?              %3F               ?                ?          ?                   %3F
@         %40        %40               @              %40               @                @          @                   %40
[         %5b        %5b               [              %5B               %5B              [          [                   %5B
]         %5d        %5d               ]              %5D               %5D              ]          ]                   %5D
\         %5c        %5c               \              %5C               %5C              \          \                   %5C
^         %5e        %5e               ^              %5E               %5E              ^          ^                   %5E
_         _          _                 _              _                 _                _          _                   %5F
`         %60        %60               `              %60               %60              `          `                   %60
{         %7b        %7b               {              %7B               %7B              {          {                   %7B
}         %7d        %7d               }              %7D               %7D              }          }                   %7D
|         %7c        %7c               |              %7C               %7C              |          |                   %7C
~         %7e        %7e               ~              ~                 ~                ~          ~                   %7E

Ā         %c4%80     %u0100            %c4%80         %C4%80            %C4%80           Ā          Ā                   [OoR]
ā         %c4%81     %u0101            %c4%81         %C4%81            %C4%81           ā          ā                   [OoR]
Ē         %c4%92     %u0112            %c4%92         %C4%92            %C4%92           Ē          Ē                   [OoR]
ē         %c4%93     %u0113            %c4%93         %C4%93            %C4%93           ē          ē                   [OoR]
Ī         %c4%aa     %u012a            %c4%aa         %C4%AA            %C4%AA           Ī          Ī                   [OoR]
ī         %c4%ab     %u012b            %c4%ab         %C4%AB            %C4%AB           ī          ī                   [OoR]
Ō         %c5%8c     %u014c            %c5%8c         %C5%8C            %C5%8C           Ō          Ō                   [OoR]
ō         %c5%8d     %u014d            %c5%8d         %C5%8D            %C5%8D           ō          ō                   [OoR]
Ū         %c5%aa     %u016a            %c5%aa         %C5%AA            %C5%AA           Ū          Ū                   [OoR]
ū         %c5%ab     %u016b            %c5%ab         %C5%AB            %C5%AB           ū          ū                   [OoR]

The columns represent encodings as follows:

UrlEncoded: HttpUtility.UrlEncode

UrlEncodedUnicode: HttpUtility.UrlEncodeUnicode

UrlPathEncoded: HttpUtility.UrlPathEncode

EscapedDataString: Uri.EscapeDataString

EscapedUriString: Uri.EscapeUriString

HtmlEncode: HttpUtility.HtmlEncode

HtmlAttributeEncode: HttpUtility.HtmlAttributeEncode

HexEscape: Uri.HexEscape

NOTES:

  1. HexEscape can only handle the first 255 characters. Therefore it throws an ArgumentOutOfRange exception for the Latin A-Extended characters (eg Ā).

  2. The characters in my table are not ordered exactly in ascending ASCII/Unicode order (eg [, ], \ are out of order).

saeed
  • 2,477
  • 2
  • 23
  • 40
0

you may want to look at URLEncode URL Encoding using C# which converts these characters into postable data

Community
  • 1
  • 1
bizzehdee
  • 20,289
  • 11
  • 46
  • 76
0

Try to add <meta charset='utf-8'> or <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> to your page's tag.

Also check your site's web.config to see what globalization settings are set there. Setting explicitly to utf-8 might help.
Reference: http://msdn.microsoft.com/en-us/library/39d1w2xf.aspx

Ramunas
  • 3,853
  • 1
  • 30
  • 31
0

Basic http url encoding would swap out your $ for %24, however that doesn't sound like it's the problem here. You may want to use URLEncode and then decode it on the other end. Or, if you're sending this as part of the payload you may need to specify the character encoding that you're using (one side is using ASCII the other UTF-8 or something to this effect, and you're getting garbage as a result).

evanmcdonnal
  • 46,131
  • 16
  • 104
  • 115