VB.Net Convert text to WWW form

时间:2017-08-30 20:37:10

标签: vb.net encoding utf-8 httpwebrequest

I want to convert text into the WWW form.

E.g: amzn1.echo-api.session.[unique-value-here] should be document.getElementById("quizQ").innerHTML = "<h3>which icon is used for github?</h3><br>" + "<li>&#xf296;</li><br>" + "<li>&#xf113;</li><br>" + "<li>&#xf281</li>", <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <header> </header> <main> <div id="quizQ"> </div> </main> <footer> </footer> should be @ etc...

There's fine encoder here, but i want to do it in VB.Net.

I need this for httpwebrequest, i think it has something to do with x-www-form-urlencoded.

1 个答案:

答案 0 :(得分:1)

您可以使用Uri.EscapeDataString() method

Dim OriginalURL As String = "http://www.example.com/some file with spaces.php?q1=plus+&q2=at@&q3=svenska språkets 'ö'"
Dim EncodedURL As String = Uri.EscapeDataString(OriginalURL)

在线测试: https://ideone.com/h5fqm1

如果您只想转义部分网址,但仍保留有效组件,例如: / = ? &(等),请使用Uri.EscapeUriString()