proxysettings for MSXML2 (1 Viewer)

kasmax

Registered User.
Local time
Today, 16:51
Joined
Jun 4, 2012
Messages
38
Hi

I have vba code to access a website to send sms. this code works fine when the internet explorer has no proxy. but it never works when using internet explorer with proxy. i have tried everything but cant find a solution. the code im using is:

Code:
Dim objXMLHttp, sResponse
   Set objXMLHttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
 
    UserName = "user1"
    Password = "pass1"
    strMobile = Forms!Consumers!Mobile.Value
    strMsg = "txt msg " & Forms!Consumers![FirstName].Value & " " & Forms!Consumers![LastName].Value
 
    strAPIUrl = myurl 
    objXMLHttp.setProxy "2", myproxy, "<8080>"
    objXMLHttp.Open "POST", strAPIUrl, False, UserName, Password
   objXMLHttp.setProxyCredentials "HDWA\\k1, p1"
    objXMLHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
 
    objXMLHttp.send ("destination=" & URLEncode(strMobile) & "&text=" & URLEncode(strMsg))
 
sResponse = objXMLHttp.responseText
MsgBox sResponse

can someone please help me.

many thanks in advance
 

kasmax

Registered User.
Local time
Today, 16:51
Joined
Jun 4, 2012
Messages
38
i do find a question about my issue mentioned above. in my internet explorer lan setting its set to autocofig and a heep web address is entered in the address.

i am not expert in this so can someone plz tell me that is this just the address to get proxy settings not the actual proxy settings?

and if so then how can i get actual proxy settings?

ill really appritiate the help
 

mattkorguk

Registered User.
Local time
Today, 09:51
Joined
Jun 26, 2007
Messages
301
Hi,
I have had the same issues with proxy settings just today! :banghead:
Eventually I went with adding the proxy username and password to the form and then pass this into the vb. (The username can be catured using;
Code:
Set oNet = CreateObject("WScript.Network")
Me.UserName = oNet.UserName

This is the function I built on;
Code:
Function SendMessage(sUserName, sPassword, sMobileNumber, sSenderNumberorName, sMessage)
On Error GoTo SMSerr
Dim xmlhttp As Object
Set xmlhttp = New WinHttpRequest
Dim sResponse, sUN, sPW, sTO, sFR, sMESS, ProxyUser, ProxyPword
ProxyUser = [Forms]![frmSend_SMS].[ProxyUser]
ProxyPword = "name\" & [Forms]![frmSend_SMS].[ProxyPword]
sUN = URLEncode(sUserName)
sPW = URLEncode(sPassword)
sTO = URLEncode(sMobileNumber)
sFR = URLEncode(sSenderNumberorName)
sMESS = URLEncode(sMessage)
    xmlhttp.Open "GET", "[URL]http://www.textapp.net/webservice/httpservice.aspx[/URL]?", False
    xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    xmlhttp.setProxy HTTPREQUEST_PROXYSETTING_PROXY, "servername:port", "*.textapp.net"
    xmlhttp.SetCredentials ProxyUser, ProxyPword, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
    xmlhttp.Send ("method=sendsms&returncsvstring=false " & _
                "&externallogin=" & sUN & "&password=" & sPW & _
                "&clientbillingreference=clientbillingreference" & _
                "&clientmessagereference=clientmessagereference" & _
                "&originator=" & sFR & _
                "&destinations=" & sTO & "&body=" & sMESS & "&validity=72&charactersetid=2" & _
                "&replymethodid=1&replydata=&statusnotificationurl=")
    sResponse = xmlhttp.responseText
Set xmlhttp = Nothing
SendMessage = sResponse
Exit Function
SMSerr:
MsgBox Err.Description & " / " & Err.Number
End Function
You'll also need the url encoding bit too.
Code:
Function URLEncode(strData)
Dim i, strTemp, strChar, strOut, intAsc
strTemp = Trim(strData)
For i = 1 To Len(strTemp)
strChar = Mid(strTemp, i, 1)
intAsc = Asc(strChar)
If (intAsc >= 48 And intAsc <= 57) Or _
(intAsc >= 97 And intAsc <= 122) Or _
(intAsc >= 65 And intAsc <= 90) Then
strOut = strOut & strChar
Else
strOut = strOut & "%" & Hex(intAsc)
End If
Next
URLEncode = strOut
End Function
And here's the code behind my form;
Code:
   Dim sMobileNumber1 As String
    DoCmd.SetWarnings False
    Me.Refresh
    If Len(Me.sMessage) > 160 Then
        MsgBox "Length of text message cannot exceed 160 characters.  Please adjust.", vbOKOnly, "Messaging Error"
        Forms!frmSend_SMS!sMessage.SetFocus
 
        Exit Sub
 
    End If
    If Left(Me.sMobileNumber, 1) = 0 Then
        sMobileNumber1 = 44 & Mid(Me.sMobileNumber, 2)
    End If
 
    SendMessage Me.sUserName, Me.sPassword, sMobileNumber1, Me.sSenderNumberorName, Me.sMessage
    DoCmd.OpenQuery "qrySMS-Note"
    MsgBox "Your message has been sent to " & Me.sMobileNumber & ".", vbOKOnly, "Sent"
    DoCmd.Close acForm, "frmSend_SMS", acSaveNo
    [Forms]![frmIndividual].SMSsent = "Yes"
    DoCmd.SetWarnings True
The query 'qrySMS-Note' just adds a note stating that a text has been sent. :D
I hope that helps you in some way, grab whatever helps!
 

Users who are viewing this thread

Top Bottom