 |
| 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
|
|
|
|

April 27th, 2008, 10:36 PM
|
|
Registered User
|
|
Join Date: Apr 2008
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!
|
|

April 28th, 2008, 03:04 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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 -/
|
|

April 28th, 2008, 04:38 AM
|
|
Registered User
|
|
Join Date: Apr 2008
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!
|
|

April 28th, 2008, 05:14 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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 -/
|
|

April 29th, 2008, 01:54 AM
|
|
Registered User
|
|
Join Date: Apr 2008
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

April 29th, 2008, 01:56 AM
|
|
Registered User
|
|
Join Date: Apr 2008
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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()
|
|

April 29th, 2008, 02:42 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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 -/
|
|

April 29th, 2008, 03:05 AM
|
|
Registered User
|
|
Join Date: Apr 2008
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.......
|
|

April 29th, 2008, 03:17 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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 -/
|
|

June 9th, 2010, 05:44 PM
|
|
Registered User
|
|
Join Date: Jun 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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()
|
|
 |