Reno
Reno

Reputation: 1319

How to encode html and send via HTTP Post

I am trying send html elements via http post. How safely encode and decode html string? HtmlEncode doesn't help, because it doesn't encode & and it looks as new parameter.

Upvotes: 1

Views: 2198

Answers (4)

Matthew
Matthew

Reputation: 25803

You need to encode the same way you would encode a query string.

string myPostVars = string.Format(
    "myHtml={0}&myInt={1}",
    HttpUtility.UrlEncode("<div>This is my div</div>"),
    90210
);

Upvotes: 1

Alex Butenko
Alex Butenko

Reputation: 3774

The safest way to pass anything via POST is to convert it into base64. Try this.

Upvotes: 1

HatSoft
HatSoft

Reputation: 11201

Please use HttpUtility.UrlEncode() for it

Upvotes: 2

Matt
Matt

Reputation: 1796

You probably want to URLEncode not HTMLEncode

http://msdn.microsoft.com/en-us/library/zttxte6w.aspx

Upvotes: 1

Related Questions