Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. UrlEncode Problem

UrlEncode Problem

Scheduled Pinned Locked Moved C#
csharpphphelptutorial
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    snouto
    wrote on last edited by
    #1

    Hello everybody in this forum when i encode non ascii characters in post method in http using HTTPUtility.URLEncode in C# it gives me an output of encoded string but when i encode the same word in php using urlencode function it gives me a different output in php it is almost the half encoded string from the one from C# output. the word that is encoded is : السلام عليكم in C# ====== %d8%a7%d9%84%d8%b3%d9%84%d8%a7%d9%85+%d8%b9%d9%84%d9%8a%d9%83%d9%85 in php : ======== %C7%E1%D3%E1%C7%E3%20%DA%E1%ED%DF%E3 Almost the half string in php output i need to output in C# the same encoded string as the output from php i don't know how to make it

    Human knowledge belongs to the world.

    A L L 3 Replies Last reply
    0
    • S snouto

      Hello everybody in this forum when i encode non ascii characters in post method in http using HTTPUtility.URLEncode in C# it gives me an output of encoded string but when i encode the same word in php using urlencode function it gives me a different output in php it is almost the half encoded string from the one from C# output. the word that is encoded is : السلام عليكم in C# ====== %d8%a7%d9%84%d8%b3%d9%84%d8%a7%d9%85+%d8%b9%d9%84%d9%8a%d9%83%d9%85 in php : ======== %C7%E1%D3%E1%C7%E3%20%DA%E1%ED%DF%E3 Almost the half string in php output i need to output in C# the same encoded string as the output from php i don't know how to make it

      Human knowledge belongs to the world.

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      Actually if there is some unicode, the querystring sometimes bigger than what needed. I dont know what is happening inside urlencode of PHP. Perhaps it should be doing the same thing, but using some other Charset. :)

      Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


      My Latest Articles-->** Simplify Code Using NDepend
      Basics of Bing Search API using .NET
      Microsoft Bing MAP using Javascript

      1 Reply Last reply
      0
      • S snouto

        Hello everybody in this forum when i encode non ascii characters in post method in http using HTTPUtility.URLEncode in C# it gives me an output of encoded string but when i encode the same word in php using urlencode function it gives me a different output in php it is almost the half encoded string from the one from C# output. the word that is encoded is : السلام عليكم in C# ====== %d8%a7%d9%84%d8%b3%d9%84%d8%a7%d9%85+%d8%b9%d9%84%d9%8a%d9%83%d9%85 in php : ======== %C7%E1%D3%E1%C7%E3%20%DA%E1%ED%DF%E3 Almost the half string in php output i need to output in C# the same encoded string as the output from php i don't know how to make it

        Human knowledge belongs to the world.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        .NET String datatype is Unicode. I do not have much knowledge about php, perhaps it is not Unicode. That explains why it is half the size of its C# counterpart.

        1 Reply Last reply
        0
        • S snouto

          Hello everybody in this forum when i encode non ascii characters in post method in http using HTTPUtility.URLEncode in C# it gives me an output of encoded string but when i encode the same word in php using urlencode function it gives me a different output in php it is almost the half encoded string from the one from C# output. the word that is encoded is : السلام عليكم in C# ====== %d8%a7%d9%84%d8%b3%d9%84%d8%a7%d9%85+%d8%b9%d9%84%d9%8a%d9%83%d9%85 in php : ======== %C7%E1%D3%E1%C7%E3%20%DA%E1%ED%DF%E3 Almost the half string in php output i need to output in C# the same encoded string as the output from php i don't know how to make it

          Human knowledge belongs to the world.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Your C# string has 12 bytes, a plus, and 10 bytes. Your PHP string has 6 bytes, a space, and 5 bytes. Hence in PHP you're using a special character set, capable of representing all required chars as a single byte; whereas in C# you're using two bytes per char. Suggestion: find out what the character set ("codepage") is you need, then use new Encoding(codepage) and its GetBytes() method. :)

          Luc Pattyn


          I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups