Hello,
I'm sending a JSON with an XML to server and sometimes I get an error:
{"":{"Value":"","Messages":["Invalid character in the given encoding. Line 21, position 47."]}}
It looks like the message that I'm sending is not in UTF-8 format.
Here is the code (and a strip down XML) that gives me this error:
This line in XML triggers this error:Code:Public Sub sendtoserver() Dim objHTTP As New MSXML2.ServerXMLHTTP60 Dim strJSON As String Dim Url As String Dim strUserName As String Dim strPassword As String Dim strCompanyId As String Dim strSoftwareId As String Dim strXML As String Dim result As String strXML = "" strXML = strXML & "<?xml version='1.0' encoding='utf-8'?>" strXML = strXML & "<OutgoingInvoicesData xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns='http://fina.hr/eracun/erp/OutgoingInvoicesData/v3.2'>" strXML = strXML & " <Header>" strXML = strXML & " <SupplierID>435455335</SupplierID>" strXML = strXML & " <InvoiceType>1</InvoiceType>" strXML = strXML & " </Header>" strXML = strXML & " <OutgoingInvoice>" strXML = strXML & " <SupplierInvoiceID>1212-1-1</SupplierInvoiceID>" strXML = strXML & " <BuyerID>455465456</BuyerID>" strXML = strXML & " <InvoiceEnvelope>" strXML = strXML & " <Invoice xmlns:cbc='urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2' xmlns:sac='urn:oasis:names:specification:ubl:schema:xsd:SignatureAggregateComponents-2' xmlns:ext='urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2' xmlns:cac='urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2' xmlns:sig='urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2' xsi:schemaLocation='urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 HRInvoice.xsd' xmlns='urn:oasis:names:specification:ubl:schema:xsd:Invoice-2'>" strXML = strXML & " <ext:UBLExtensions>" strXML = strXML & " <ext:UBLExtension>" strXML = strXML & " <cbc:ID>HRINVOICE1</cbc:ID>" strXML = strXML & " <cbc:Name>InvoiceIssuePlaceData</cbc:Name>" strXML = strXML & " <ext:ExtensionAgencyID>MINGORP</ext:ExtensionAgencyID>" strXML = strXML & " <ext:ExtensionAgencyName>MINGORP</ext:ExtensionAgencyName>" strXML = strXML & " <ext:ExtensionAgencyURI>MINGORP</ext:ExtensionAgencyURI>" strXML = strXML & " <ext:ExtensionURI>urn:invoice:hr:issueplace</ext:ExtensionURI>" strXML = strXML & " <ext:ExtensionReasonCode>MandatoryField</ext:ExtensionReasonCode>" strXML = strXML & " <ext:ExtensionReason>Mjesto izdavanja raèuna prema Pravilniku o PDV-u</ext:ExtensionReason>" strXML = strXML & " <ext:ExtensionContent>" strXML = strXML & " <ext:InvoiceIssuePlace>MyTown</ext:InvoiceIssuePlace>" strXML = strXML & " </ext:ExtensionContent>" strXML = strXML & " </ext:UBLExtension>" strXML = strXML & " </ext:UBLExtensions>" strXML = strXML & " </Invoice>" strXML = strXML & " </InvoiceEnvelope>" strXML = strXML & " </OutgoingInvoice>" strXML = strXML & "</OutgoingInvoicesData>" Url = "http://demo.webadress.com/apis/v2/send/" strUserName = "ThisIsTheUserName" strPassword = "PaSSworD" strCompanyId = "33122611302" strSoftwareId = "Test-001" strJSON = "" strJSON = strJSON & "{" & Chr(34) & "Username" & Chr(34) & ": " & strUserName & "," strJSON = strJSON & Chr(34) & "Password" & Chr(34) & ": " & Chr(34) & strPassword & Chr(34) & "," strJSON = strJSON & Chr(34) & "CompanyId" & Chr(34) & ": " & Chr(34) & strCompanyId & Chr(34) & "," strJSON = strJSON & Chr(34) & "SoftwareId" & Chr(34) & ": " & Chr(34) & strSoftwareId & Chr(34) & "," strJSON = strJSON & Chr(34) & "File" & Chr(34) & ": " & Chr(34) & strXML & Chr(34) & "}" objHTTP.Open "POST", Url, False objHTTP.setRequestHeader "Content-type", "application/json" objHTTP.send (strJSON) result = objHTTP.responseText ExitSub: Set objHTTP = Nothing End Sub
It contains a special character èCode:<ext:ExtensionReason>Mjesto izdavanja raèuna prema Pravilniku o PDV-u</ext:ExtensionReason>"
How could I convert the strJSON to UTF-8?




Reply With Quote
