Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
| Search | Today's Posts | Mark Forums Read
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 27th, 2008, 10:36 PM
Registered User
 
Join Date: Apr 2008
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Post a xml file to an URL?

hi,
newbie here. how do i post a xml file to an URL? vb, visual web developer 2008
thank you!

 
Old April 28th, 2008, 03:04 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

If you requirements are simple then you can use the WebClient.UploadFile method.

If you need finer control over what is happening then you will have to use HttpWebRequest/HttpWebResponse. Do a google for "HttpWebRequest upload file" for more examples.

/- Sam Judson : Wrox Technical Editor -/
 
Old April 28th, 2008, 04:38 AM
Registered User
 
Join Date: Apr 2008
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i need to send a request to the web server (an url) through xml, so to get response from them, do i use httpwebrequest and how about the coding in vb.net? great thanks!

 
Old April 28th, 2008, 05:14 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

What part of "use WebClient.UploadFile() method" didn't you understand?

If you expect me to write your homework/assignment for you then are mistaken.

/- Sam Judson : Wrox Technical Editor -/
 
Old April 29th, 2008, 01:54 AM
Registered User
 
Join Date: Apr 2008
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have tried out this codes, but it keeps on return me 500 internal server error, anything wrong in the codes?thanks!

Dim httpreq As System.Net.HttpWebRequest
        Dim httpres As System.Net.HttpWebResponse
        Dim strXMLDoc
        Dim strURI As String
        Dim fileName As String
        fileName = "C:\citySearchRequest.xml"
        'fileName = fileName.TrimStart("\")
        Try
            strXMLDoc = fileName

            strURI = "https://test.miki.co.uk/interface/XMLRequest?xml="
            httpreq = Net.WebRequest.Create(strURI)
            'using the POST method for form processing
            httpreq.Method = "POST"
            'set the content type to process text and xml alike
            httpreq.ContentType = "text/xml"
            httpreq.AllowWriteStreamBuffering = True
            'wrap the request with a text-based writer
            Dim streamXML As New System.IO.StreamWriter(httpreq.GetRequestStream())

            'httpreq.SendChunked = True
            'wrap the request with a text-based writer
            ' Dim streamXML As New System.IO.StreamWriter(httpreq.GetRequestStream()) 'this won't work if there is security (https) on the site
            'write the xml into the stream
            streamXML.WriteLine(GetTextFromXMLFile(strXMLDoc))
            'close the xml file
            streamXML.Close()
            'Get The Response
            httpres = httpreq.GetResponse

        Catch ex As Exception
        End Try

    End Sub



    Public Function GetTextFromXMLFile(ByVal str As String) As String
        Dim ReadXML As New System.IO.StreamReader(str)
        Dim ret As String
        ret = ReadXML.ReadToEnd()
        ReadXML.Close()
        GetTextFromXMLFile = ret


    End Function

 
Old April 29th, 2008, 01:56 AM
Registered User
 
Join Date: Apr 2008
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i have tried these codes also, and getting the same error

 Dim objRequest As HttpWebRequest = CType(WebRequest.Create("https://test.miki.co.uk/interface/XMLRequest?xml="), HttpWebRequest)
        Dim StrData As String
        Dim objXMLDoc As New System.Xml.XmlDocument()
        objXMLDoc.Load(".\citySearchRequest.xml") 'xml data I need to send
        StrData = objXMLDoc.OuterXml



        objRequest.Method = "post"
        Dim encoding As New System.Text.ASCIIEncoding()
        Dim byte1 As Byte() = Text.Encoding.UTF8.GetBytes(StrData)
        objRequest.ContentLength = byte1.Length
        objRequest.ContentType = "application/x-www-form-urlencoded"
        objRequest.KeepAlive = False



        Dim streamToSend As Stream = objRequest.GetRequestStream()
        'Response.Write("Number of characters returned: " & byte1.Length & "<br>")
        streamToSend.Write(byte1, 0, byte1.Length)
        streamToSend.Close()





        Dim objResponse As HttpWebResponse = CType(objRequest.GetResponse(), HttpWebResponse)
        'Dim objResponse As HttpWebResponse = objRequest.GetResponse()
        Dim StreamReader As IO.StreamReader
        StreamReader = New IO.StreamReader(objResponse.GetResponseStream())
        Dim xmlDoc As New XmlDocument()
        xmlDoc.LoadXml(StreamReader.ReadToEnd())
        Response.Write("RETURN XML:" & xmlDoc.InnerXml)



        Dim newsr As New StreamReader(objResponse.GetResponseStream())
        Dim respText As String = newsr.ReadToEnd()
        newsr.Close()
        Console.WriteLine(respText)





        Dim sr As New System.IO.StringReader(xmlDoc.InnerXml)
        Dim doc As New XmlDocument
        doc.Load(sr)
        Dim reader As New XmlNodeReader(doc)
        While reader.Read()
            Select Case reader.NodeType
                Case XmlNodeType.Element
                    If reader.Name = "response" Then
                        Response.Write(reader.GetAttribute("msg"))
                    End If

                    If reader.Name = "reaction" Then
                        Response.Write("<br />ID " & reader.GetAttribute("id"))
                    End If
            End Select
        End While



        StreamReader.Close()


 
Old April 29th, 2008, 02:42 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

A HTTP 500 error means that the server is rejecting what you are sending it, or there is an error in the code on the server.

There is no way of telling what that might be from your code.

/- Sam Judson : Wrox Technical Editor -/
 
Old April 29th, 2008, 03:05 AM
Registered User
 
Join Date: Apr 2008
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

is it something wrong with the web server?
but when i try to put the xml data inside the url like below, it works perectly...


https://test.miki.co.uk/interface/XMLRequest?xml=<?xml version="1.0" encoding="UTF-8"?><citySearchRequest requestType="citySearchRequest" versionNumber="4.1.0"><requestAuditInfo><agentCode >XXX001</agentCode><requestPassword>XXX</requestPassword.......

 
Old April 29th, 2008, 03:17 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Quote:
quote: is it something wrong with the web server?
How on earth do you expect us to know that?

/- Sam Judson : Wrox Technical Editor -/
 
Old June 9th, 2010, 05:44 PM
Registered User
 
Join Date: Jun 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Post a xml file to an url

friends, I need a good solution. I have the same problem. I tried everything. [:)]



Dim xml As String = "<?xml version=""1.0""?><GET_ASN><SENDER_ID>1000050000</SENDER_ID><TSF_NO>3016750000</TSF_NO><CEDIS>9999990000</CEDIS></GET_ASN>"
Dim objRequest As HttpWebRequest = CType(WebRequest.Create("http://Server/Invoke/PPPP.pubsss/runOnline?xmlIn="), HttpWebRequest)

objRequest.Method = "post"
Dim byte1 As Byte() = Text.Encoding.UTF8.GetBytes(xml)
objRequest.ContentLength = byte1.Length
objRequest.ContentType = "text/xml"
objRequest.KeepAlive = False


Dim streamToSend As Stream = objRequest.GetRequestStream()
streamToSend.Write(byte1, 0, byte1.Length)
streamToSend.Close()


Dim objResponse As HttpWebResponse = CType(objRequest.GetResponse(), HttpWebResponse)
Dim StreamReader As IO.StreamReader
StreamReader = New IO.StreamReader(objResponse.GetResponseStream())
Response.Write("RETURN XML:" & StreamReader.ReadToEnd())
StreamReader.Close()




Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I post a XML file to an URL using VB? chengjianjin Visual Basic 2005 Basics 3 April 28th, 2008 05:24 AM
Using web request and response to post data to URl cgmenon .NET Framework 1.x 0 July 13th, 2006 10:39 AM
call to url while keep the form post parameters Goldwind Classic ASP Basics 0 December 25th, 2005 01:21 PM
Posting an XML file to an URL from C virajithasarma XML 0 October 7th, 2005 01:47 AM
GET URL FROM XML POST kevorkian Classic ASP XML 4 December 23rd, 2004 11:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.