Aşağıda VB ile yazılmış kodu ,VBA ile çalışacak hale nasıl getiririz. Konu ile ilgili fikri olan değerli hocalarımdan yadrdım rica ediyorum.
Not: Kodlar NETGSM firmasının API kodlarıdır. UserForm üzerinden mesaj göndermek için böyle bir çalışmaya ihtiyacım var..
Şimdiden teşekkürlerimi sunuyorum.
Kod:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim a As String
Dim gelen
a = "<?xml version='1.0' encoding='iso-8859-9'?>
<mainbody>
<company dil='TR'>Netgsm</company>
<header>
<usercode>KullaniciAdi</usercode>
<password>Sifre</password>
<type>1:n</type>
<msgheader>Baslik</msgheader>
</header>
<body>
<msg>
<![CDATA[Mesaj Metnim]]>
</msg>
<no>051212312312</no>
<no>051212312312</no>
</body>
</mainbody>"
gelen = WRequest("https://api.netgsm.com.tr/sms/send/xml", "POST", a)
MsgBox(gelen)
End Sub
Function WRequest(ByVal URL As String, ByVal method As String, ByVal POSTdata As String) As String
Dim responseData As String = ""
Try
Dim hwrequest As Net.HttpWebRequest = Net.WebRequest.Create(URL)
hwrequest.Accept = "*/*"
hwrequest.AllowAutoRedirect = True
hwrequest.UserAgent = "http_requester/0.1"
hwrequest.Timeout = 60000
hwrequest.Method = method
If hwrequest.Method = "POST" Then
hwrequest.ContentType = "application/x-www-form-urlencoded"
Dim postByteArray As Byte() = New System.Text.UTF8Encoding(True).GetBytes(POSTdata)
' Dim encoding As New Text.ASCIIEncoding() 'Use UTF8Encoding for XML requests
' Dim postByteArray() As Byte = encoding.GetBytes(POSTdata)
hwrequest.ContentLength = postByteArray.Length
Dim postStream As IO.Stream = hwrequest.GetRequestStream()
postStream.Write(postByteArray, 0, postByteArray.Length)
postStream.Close()
End If
Dim hwresponse As Net.HttpWebResponse = hwrequest.GetResponse()
If hwresponse.StatusCode = Net.HttpStatusCode.OK Then
Dim responseStream As IO.StreamReader = New IO.StreamReader(hwresponse.GetResponseStream())
responseData = responseStream.ReadToEnd()
End If
hwresponse.Close()
Catch e As Exception
responseData = "An error occurred: " & e.Message
End Try
Return responseData
End Function