• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1200
  • Last Modified:

I have this xmlhttp post how do I use this in vb.net.

I have the below asp code that works but I need to get it over to vb.net. How would I accomplish this?
Set xmlhttp = server.createobject("MSXML2.ServerXMLHttp")
xmlhttp.open "POST","http://192.168.150.10/AttachDoc_URL/GenAttachDoc.asp", True
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
	xmlhttp.setTimeouts 10000,10000,30000,60000
	strRequest = "URL="& URL & "&" & AdditionalInfo
	xmlhttp.send Replace(strRequest," ","")
	xmlhttp.waitForResponse 1

Open in new window

0
-cr-
Asked:
-cr-
  • 2
1 Solution
 
PaulHewsCommented:
Import the System.Net namespace.
Dim Req As HttpWebRequest
        Req = CType(WebRequest.Create("http://192.168.150.10/AttachDoc_URL/GenAttachDoc.asp"), HttpWebRequest)  'Correct login URL
        Req.Method = "POST"
        Req.ContentType = "application/x-www-form-urlencoded"
 
        Dim PostData() As Byte = System.Text.Encoding.Default.GetBytes("URL=" & URL & "&" & AdditionalInfo)
        Req.GetRequestStream.Write(PostData, 0, PostData.Length)
        Req.GetRequestStream.Close()
 
        Dim resp As HttpWebResponse = CType(Req.GetResponse, HttpWebResponse)
 
        Dim sr As New System.IO.StreamReader(resp.GetResponseStream)
 
        Dim ResponseText As String = sr.ReadToEnd
        Debug.WriteLine(ResponseText)
        sr.Dispose()
        resp.Close()

Open in new window

0
 
vb_jonasCommented:
I use this:
Imports System.Net
 
    Public Function ReadDataSetFromXMLurl(ByVal url As String) As DataSet
 
        Dim request As HttpWebRequest
        Dim response As HttpWebResponse = Nothing
        Dim ds As DataSet
 
        Try
            request = DirectCast(WebRequest.Create(url), HttpWebRequest)
            request.Timeout = 60 * 1000 
            response = DirectCast(request.GetResponse(), HttpWebResponse)
            ds = New DataSet()
            ds.ReadXml(response.GetResponseStream())
        Finally
            If Not response Is Nothing Then response.Close()
        End Try
 
        Return ds
 
    End Function

Open in new window

0
 
-cr-Author Commented:
If a username and password are required how would I do that using the above examples?
0
 
vb_jonasCommented:
Hi!

Add:
Dim cred As New NetworkCredential(username,password) ' and ,domain if needed
request.Credantials=cred

before .GetResponse()
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now