473,796 Members | 2,903 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

post large xml files

I have a routine I call to post XML from vb.net to a url over http

It can be the XML file can be quite a size sometime I expect it to
exceed 10mb.
I started using a routine to post the file to a URL from vb.net, but
didnt realise there would be a restiction on post size.
So from this function :

Dim result As String = ""
Dim mywriter As IO.StreamWriter
Dim strXML = xmlDoc.InnerXml ()
Dim bojRequest As System.Net.Http WebRequest =
System.Net.Http WebRequest.Crea te(postUrl)

bojRequest.Meth od = "POST"
bojRequest.Cont entLength = strXML.Length
bojRequest.Cont entType = "text/xml"

Dim myCred As New System.Net.Netw orkCredential(p ostUsername,
postPassword)
bojRequest.Cred entials = myCred

Try
mywriter = New
IO.StreamWriter (bojRequest.Get RequestStream() )
mywriter.Write( strXML)
mywriter.Flush( )
mywriter.Close( )
mywriter = Nothing

Dim objResponse As System.Net.Http WebResponse =
bojRequest.GetR esponse()
Dim sr As IO.StreamReader
sr = New IO.StreamReader (objResponse.Ge tResponseStream ())
result = sr.ReadToEnd
sr.Close()
sr = Nothing
Catch ex As Exception
Return ex.Message
End Try

I got this return:
Bytes to be written to the stream exceed the Content-Length bytes size
specified, but the function works when sizes are good.
Im not sure how to fix this so I googled areound and came up with this:

Try
Dim req As WebRequest
Dim RequestStream As Stream
Dim ReceiveStream As Stream
Dim encode As Encoding
Dim sr As StreamReader
Dim payload As String
req = WebRequest.Crea te(postUrl)
req.Method = "POST"
req.ContentType = "text/xml"
Dim SomeBytes() As Byte
Dim UrlEncoded As New StringBuilder
Dim reserved() As Char = {ChrW(63), ChrW(61), ChrW(38)}
Dim result As WebResponse

payload = xmlDoc.InnerXml
If payload <Nothing Then
Dim i As Integer = 0
Dim j As Integer
While i < payload.Length
j = payload.IndexOf Any(reserved, i)
If j = -1 Then

UrlEncoded.Appe nd(HttpUtility. UrlEncode(paylo ad.Substring(i,
payload.Length - i)))

'UrlEncoded.App end(URLEncode(p ayload.Substrin g(i, payload.Length - i)))
Exit While
End If

UrlEncoded.Appe nd(HttpUtility. UrlEncode(paylo ad.Substring(i, j - i)))
UrlEncoded.Appe nd(payload.Subs tring(j, 1))
i = j + 1
End While
SomeBytes =
System.Text.Enc oding.UTF8.GetB ytes(UrlEncoded .ToString())
req.ContentLeng th = SomeBytes.Lengt h
RequestStream = req.GetRequestS tream()
RequestStream.W rite(SomeBytes, 0, SomeBytes.Lengt h)
RequestStream.C lose()
Else
req.ContentLeng th = 0
End If
result = req.GetResponse ()
ReceiveStream = result.GetRespo nseStream()
encode = System.Text.Enc oding.GetEncodi ng("utf-8")
sr = New StreamReader(Re ceiveStream, encode)

Console.WriteLi ne()
Console.WriteLi ne("Response stream received")
Dim read(256) As Char
Dim count As Integer = sr.Read(read, 0, 256)

Console.WriteLi ne("HTML...")
Console.WriteLi ne()
Do While count 0
Dim str As String = New String(read, 0, count)
Console.Write(s tr)
count = sr.Read(read, 0, 256)
Loop
Console.WriteLi ne("")
Catch Exc As Exception
Console.WriteLi ne()
Console.WriteLi ne("The request URI could not be found or
was malformed")
Finally
If Not result Is Nothing Then
result.Close()
End If
End Try

The function runs through without error, but doesnt post
anything..im not sure why its not posting, the url and credentials are
fine.
So I end up with 2 questions, one how to run a procedure to
post large xml files over http, and if anyone knows how to use
compression to reduce the file size sent?

Oct 1 '06 #1
2 5899


andy wrote:

Dim strXML = xmlDoc.InnerXml ()
What is xmlDoc? A System.Xml.XmlD ocument instance? If so if you want to
write that to a stream then you can simply do e.g.
Dim bojRequest As System.Net.Http WebRequest =
System.Net.Http WebRequest.Crea te(postUrl)

bojRequest.Meth od = "POST"
bojRequest.Cont entType = "text/xml"

Dim myCred As New System.Net.Netw orkCredential(p ostUsername,
postPassword)
bojRequest.Cred entials = myCred
Stream requestStream = bojRequest.GetR equestStream()
xmlDoc.Save(req uestStream)

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Oct 1 '06 #2
Thanks for replying Martin.
I could see what you were saying but couldnt get it to work, anyway
here is the solution i found earlier for anyone else trawling google.

Dim inputStream As New FileStream(file Path, FileMode.Open,
FileAccess.Read , FileShare.Read)
Dim inputLength As Integer = CInt(inputStrea m.Length)
Dim inputBody(input Length) As Byte
inputStream.Rea d(inputBody, 0, inputLength)
inputStream.Clo se()
' Create WebRequest and set headers
Dim req As HttpWebRequest =
CType(WebReques t.Create(postUr l), HttpWebRequest)
req.Credentials = CredentialCache .DefaultCredent ials
req.Method = "POST"
req.ProtocolVer sion = HttpVersion.Ver sion11
req.ContentType = "text/xml"
req.ContentLeng th = inputLength
If 0 < mTimeout Then
req.Timeout = mTimeout
End If
' Write the input to the request stream
Dim reqStream As Stream = req.GetRequestS tream()
reqStream.Write (inputBody, 0, inputLength)
reqStream.Close ()
It works althought im not at all sure about this functions limitations
when faced with large file sizes and would still be interested in
comments on passing xml over http with compression.
Seeing as compression reduces significantly the data been sent over the

wire and can go someway to securing raw data....
Anyone comments ?

Oct 2 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6374
by: Buddy Ackerman | last post by:
I'm trying to write files directly to the client so that it forces the client to open the Save As dialog box rather than display the file. On some occasions the files are very large (100MB+). On these files teh time that it takes until the client displays the Save As dialog can be extrordinarily long (3+ minutes). I don't understand why. I was initiall using the format: Respnse.writefile("filepath", offset, length) but that simply...
2
1970
by: jdev8080 | last post by:
We are looking at creating large XML files containing binary data (encoded as base64) and passing them to transformers that will parse and transform the data into different formats. Basically, we have images that have associated metadata and we are trying to develop a unified delivery mechanism. Our XML documents may be as large as 1GB and contain up to 100,000 images. My question is, has anyone done anything like this before?
16
4988
by: lawrence k | last post by:
I've a file upload script on my site. I just now used it to upload a small text document (10k). Everything worked fine. Then I tried to upload a 5.3 meg Quicktime video. Didn't work. I've set the POST limit in php.ini to 8 megs. What reasons, other than the POST limit, would a large upload fail?
14
2251
by: Robert S | last post by:
I am trying to use POST to transfer data to another page. When I do this, '.' characters get converted to"_". For example: #index.html: <form action="test.php" method="post"> <input type="submit" name="filename.txt"> </form> #test.php <html>
1
6322
by: Lars B | last post by:
Hey guys, I have written a C++ program that passes data from a file to an FPGA board and back again using software and DMA buffers. In my program I need to compare the size of a given file against a software buffer of size 3MB. This is needed so as to see which function to use to read from the file. As the files used range from very large (>30GB) to very small (<3MB), I have enabled large file support and I obtain the file size by using the...
6
5107
by: Brybot | last post by:
I am trying to allow HTTP POST file uploads to my web service. Currently I have it working perfectly for a SOAP/XML request reading in a byte using MemoryStream/FileStream but I cannot figure out how to encode a file on a POST to the same web service. The definition requires a base64binary encoded file, which I have tried. The form is also using a mutlipart/form-data enctype, but I either get a 500 error or 'Request format is invalid'. ...
8
6395
by: theCancerus | last post by:
Hi All, I am not sure if this is the right place to ask this question but i am very sure you may have faced this problem, i have already found some post related to this but not the answer i am looking for. My problem is that i have to upload images and store them. I am using filesystem for that. setup is something like this, their will be items/groups/user each can
4
7363
by: Wolfgang Draxinger | last post by:
I'm thinking about writing a script to upload videos to sites like YouTube or Google Video, which is usually done by a HTTP POST. The problem is, that videos, by nature are rather big files, however urllib2 wants it's Request objects being prepared beforehand, which would mean to first load the whole file to memory. I looked into pycURL, knowing that cURL can POST send files
1
3898
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
Using .NET 2.0 is it more efficient to copy files to a single folder versus spreading them across multiple folders. For instance if we have 100,000 files to be copied, Do we copy all of them to a single folder called 'All Files' Do we spread them out and copy them to multiple folders like Folder 000 - Copy files from 0 to 1000 Folder 001 - Copy files from 1000 to 2000 Folder 002 - Copy files from 2000 to 2999
0
9679
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10453
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10172
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.