You have to set the encoding for WebClient:
Dim webclient As System.Net.WebClient = New System.Net.WebClient()
webclient.Encoding = Encoding.UTF8 '<---
With webclient.Encoding = Encoding.UTF8
everything comes over as should.
题
I'm messing with the Wikipedia API trying to find the English page from a Dutch one. I get this in XML format but when I want to update the MySQL database special characters getting converted so the link becomes invalid.
For example:
The API returns this: Möhrenbach
When I save it, it becomes this: Möhrenbach
Another Example
The API returns this: Sarandi, Paraná
When I save it, it becomes this: Sarandi, Paraná
The Code I Use
'SourceString is the XML response from Wikipedia Api
Dim xmlDoc As New XmlDocument()
xmlDoc.LoadXml(sourceString)
Dim node As XmlNode = xmlDoc.SelectSingleNode("//api//query//search//p[1]")
If node IsNot Nothing Then
If node.Attributes("titlesnippet") IsNot Nothing Then
Dim titlesnippet As String = node.Attributes("titlesnippet").Value
If InStr(titlesnippet, "searchmatch") > 0 Then
WikiEN = node.Attributes("title").Value
End If
End If
End If
With this code the response Möhrenbach becomes Möhrenbach in VB.NET.
How can I save the right response?
解决方案
You have to set the encoding for WebClient:
Dim webclient As System.Net.WebClient = New System.Net.WebClient()
webclient.Encoding = Encoding.UTF8 '<---
With webclient.Encoding = Encoding.UTF8
everything comes over as should.