salve
grazie delle dritte
mi hanno dato il link al web server e user + password
dal browser riesco ad accedere e mi visualizza un file xml
dalla mia procedura mi dà errore di autenticazione
potete darmi una dritta?
grazie
'
' Ho provato a pubblicare questo WS: ( url SOAP )
' Il link ovviamente cambierà quando saremo in live su altri db o società, ma il comportamento ovviamente resterà lo stesso.
' la funzione da chiamare è ‘ReadLabel’, che richiede un valore int e un boolean, che passerai sempre a false.
' Dovrebbe rispondere true o false a seconda di ballotto trovato e letto oppure no.
'
Public Sub pfm2_WebServer_Test()
Dim sUrl As String
Dim sUser As String
Dim sPassword As String
Dim nBallotto As int
sUrl = "
http://link al webserver.."
sUser = "dominio\utente"
sPassword = "miapassword"
nBallotto =400
Call PFM_SEND_BALLOTTO(sUrl, sUser, sPassword, sBallotto)
End Sub
Function PFM_SEND_BALLOTTO(url As String, _
UserName As String, Password As String, _
Optional charset As String = "") As String
Dim xmlhttp As Object
Dim method, parameters As String
method = "ReadLabel"
parameters = "method=" & method & "&" & _
"username=" & URLEncode(UserName) & "&" & _
"password=" & URLEncode(Password)
Select Case charset
Case "UTF-8"
parameters = parameters & "&charset=UTF-8"
Case Else
End Select
Set xmlhttp = CreateObject("MSXML2.serverXMLHTTP")
xmlhttp.Open "POST", url, False
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.setRequestHeader "Content-Length", Len(parameters)
xmlhttp.send parameters
If xmlhttp.Status >= 400 And xmlhttp.Status <= 599 Then
PFM_SEND_BALLOTTO = "status=failed&message=" & _
xmlhttp.Status & " - " & xmlhttp.statusText
MsgBox "Failed " & PFM_SEND_BALLOTTO
Exit Function
End If
Dim msg As String
msg = xmlhttp.responseText
Debug.Print msg
Set xmlhttp = Nothing
PFM_SEND_BALLOTTO = msg
End Function
' riferimento
https://stackoverflow.com/questions/218181/how-can-i-url-encode-a-string-in-excel-vba
' Microsoft ActiveX Data Objects 2.8 Library.
' riferimento Microsoft ActiveX Data Objects x.x Library
'
Public Function URLEncode( _
ByVal StringVal As String, _
Optional SpaceAsPlus As Boolean = False _
) As String
Dim bytes() As Byte, b As Byte, i As Integer, space As String
If SpaceAsPlus Then space = "+" Else space = "%20"
If Len(StringVal) > 0 Then
With New ADODB.Stream
.Mode = adModeReadWrite
.Type = adTypeText
.charset = "UTF-8"
.Open
.WriteText StringVal
.Position = 0
.Type = adTypeBinary
.Position = 3 ' skip BOM
bytes = .Read
End With
ReDim result(UBound(bytes)) As String
For i = UBound(bytes) To 0 Step -1
b = bytes(i)
Select Case b
Case 97 To 122, 65 To 90, 48 To 57, 45, 46, 95, 126
result(i) = Chr(b)
Case 32
result(i) = space
Case 0 To 15
result(i) = "%0" & Hex(b)
Case Else
result(i) = "%" & Hex(b)
End Select
Next i
URLEncode = Join(result, "")
End If
End Function