Я получаю сообщение об ошибке при чтении файла XML с помощью XmlTextReader
. Первый URL-адрес нормальный, но второй URL-адрес не работает. Это нормально использовать другой URL. Только этот URL содержит ошибку.
Dim url As String
'url = "http://test.damiedu.net/testxml.xml"
'url = "http://www.hrd.go.kr/hrdp/api/apiao/APIAO0101T.do?authKey=k8V0j828FdFfjZye2mNR6tJ6kHIfkoJI&outType=1&srchTraEndDt=20150631&srchTraStDt=20150101&sortCol=TR_NM_i&returnType=XML&pageSize=20&pageNum=1&sort=ASC&srchTraPattern=C1&srchPart=-99&apiRequstPageUrlAdres=/jsp/HRDP/HRDPO00/HRDPOA40/HRDPOA40_1.jsp&apiRequstIp=211.179.124.14"
Try
Dim euckr As System.Text.Encoding
euckr = System.Text.Encoding.GetEncoding("euc-kr")
Dim Client As WebClient
Dim test As Integer
Client = New WebClient
Client.Headers("accept-langquage") = "ko"
Dim reader As XmlTextReader
reader = New XmlTextReader(Client.OpenRead(url))
test = reader.Read.ToString
Do While reader.Read
If (reader.NodeType = XmlNodeType.Element) Then
If reader.Name = "address" Then
Response.Write("address" & reader.ReadElementString())
End If
If reader.Name = "instCd" Then
Response.Write("name" & reader.ReadElementString())
End If
End If
Loop
Catch ex As Exception
MsgBox(ex.Message, "faile")
End Try
euckr = System.Text.Encoding.GetEncoding("euc-kr")
, но никогда не используете его. XML, возвращаемый URL-адресомhttp://www.hrd.go.kr/...
, действительно закодирован с помощью EUC-KR (согласно Firefox), поэтому вам необходимо его использовать. Или еще лучше используйтеDownloadStringAwareOfEncoding()
из этого ответа. - person dbc   schedule 01.06.2017"accept-langquage"
должно быть"Accept-Language"
. - person dbc   schedule 01.06.2017