byte array problem

G

Guest

I am working on a project where I will receive xml documents from clients
machines as a byte array. They will use the web browser navigate method to
post the data to my ASP.NET page. I then pick up the byte array using the
request object (XMLData=bytearray..). Can someone point me to an article that
shows me how I can do this in ASP.NET, C#?

Thanks
Danny
 
K

Kevin Spencer

Convert the byte array to a string. Create an XmlDocument instance, and use
the Load() method, passing the string to the constructor.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition
 
G

Guest

Thanks Kevin

To receive the byte array from the client should I be using
Request.InputStream ?

Assuming the method I think the clients will use to send the data to my
application, could be like this:

string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest loHttp =
(HttpWebRequest) WebRequest.Create(lcUrl);

// *** Send any POST data
string lcPostData =
"XMLData=" + HttpUtility.UrlEncode("xmldata..");

loHttp.Method="POST";
byte [] lbPostBuffer =
System.Text.Encoding.GetEncoding(1252).GetBytes(lcPostData);
loHttp.ContentLength = lbPostBuffer.Length;
 
K

Kevin Spencer

Hi Danny,

If I understand you correctly, they are using a .Net program that employs
the HttpWebRequest to send the XML data via HTTP POST?

If so, you need to create an HTML form on the fly so to speak. This is not
too hard to do. An HTTP Post is a sequence of "name=value" pairs, separated
by '&' characters, just like a QueryString, but longer. The "name" part is
the name of a form field, and the "value" part is the data for that form
field. So, for example, if you wanted to POST a form having one field named
"foo" and the value in it was "bar" your body would simply look like this:

foo=bar

Of course, this must all be URLEncoded, and sending an XML document means a
lot of URLEncoding, for all the tags and such, but using URLEncode() will do
it. So, to send a single XML document via POST would be something like:

string body = "Xml=" + HttpUtility.URLEncode(XmlString);

"Xml" would be the name of the form field.

It has to be encoded into a byte array because you are actually sending a
stream, but it becomes a string at the other end. So, your code might look
something like the following:

ASCIIEncoding encoding = new ASCIIEncoding();
Stream requestStream = null;
string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest IoHttp = (HttpWebRequest) WebRequest.Create(lcUrl);
IoHttp.Method = "POST";
IoHttp.ContentType = "application/x-www-form-urlencoded";
string body = encoding.GetBytes("Xml=" + HttpUtility.URLEncode(XmlString));
IoHttp.ContentLength = body.Length;
try
{
requestStream = IoHttp.GetRequestStream();
requestStream.Write(body, 0, body.Length);
}
catch
{
//...
}
finally
{
if (requestStream != null) requestStream.Close();
}

In your ASPX page, you just get Request.Form["Xml"] which is already a
string.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

Danny said:
Thanks Kevin

To receive the byte array from the client should I be using
Request.InputStream ?

Assuming the method I think the clients will use to send the data to my
application, could be like this:

string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest loHttp =
(HttpWebRequest) WebRequest.Create(lcUrl);

// *** Send any POST data
string lcPostData =
"XMLData=" + HttpUtility.UrlEncode("xmldata..");

loHttp.Method="POST";
byte [] lbPostBuffer =
System.Text.Encoding.GetEncoding(1252).GetBytes(lcPostData);
loHttp.ContentLength = lbPostBuffer.Length;


Kevin Spencer said:
Convert the byte array to a string. Create an XmlDocument instance, and
use
the Load() method, passing the string to the constructor.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition
 
G

Guest

Kevin thanks alot for your help. One quick question regarding this.
They will be using a .net program to post the xml data with the web browser
method. Will this still work with what you said?

Regards
Danny


Kevin Spencer said:
Hi Danny,

If I understand you correctly, they are using a .Net program that employs
the HttpWebRequest to send the XML data via HTTP POST?

If so, you need to create an HTML form on the fly so to speak. This is not
too hard to do. An HTTP Post is a sequence of "name=value" pairs, separated
by '&' characters, just like a QueryString, but longer. The "name" part is
the name of a form field, and the "value" part is the data for that form
field. So, for example, if you wanted to POST a form having one field named
"foo" and the value in it was "bar" your body would simply look like this:

foo=bar

Of course, this must all be URLEncoded, and sending an XML document means a
lot of URLEncoding, for all the tags and such, but using URLEncode() will do
it. So, to send a single XML document via POST would be something like:

string body = "Xml=" + HttpUtility.URLEncode(XmlString);

"Xml" would be the name of the form field.

It has to be encoded into a byte array because you are actually sending a
stream, but it becomes a string at the other end. So, your code might look
something like the following:

ASCIIEncoding encoding = new ASCIIEncoding();
Stream requestStream = null;
string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest IoHttp = (HttpWebRequest) WebRequest.Create(lcUrl);
IoHttp.Method = "POST";
IoHttp.ContentType = "application/x-www-form-urlencoded";
string body = encoding.GetBytes("Xml=" + HttpUtility.URLEncode(XmlString));
IoHttp.ContentLength = body.Length;
try
{
requestStream = IoHttp.GetRequestStream();
requestStream.Write(body, 0, body.Length);
}
catch
{
//...
}
finally
{
if (requestStream != null) requestStream.Close();
}

In your ASPX page, you just get Request.Form["Xml"] which is already a
string.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

Danny said:
Thanks Kevin

To receive the byte array from the client should I be using
Request.InputStream ?

Assuming the method I think the clients will use to send the data to my
application, could be like this:

string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest loHttp =
(HttpWebRequest) WebRequest.Create(lcUrl);

// *** Send any POST data
string lcPostData =
"XMLData=" + HttpUtility.UrlEncode("xmldata..");

loHttp.Method="POST";
byte [] lbPostBuffer =
System.Text.Encoding.GetEncoding(1252).GetBytes(lcPostData);
loHttp.ContentLength = lbPostBuffer.Length;


Kevin Spencer said:
Convert the byte array to a string. Create an XmlDocument instance, and
use
the Load() method, passing the string to the constructor.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

I am working on a project where I will receive xml documents from
clients
machines as a byte array. They will use the web browser navigate method
to
post the data to my ASP.NET page. I then pick up the byte array using
the
request object (XMLData=bytearray..). Can someone point me to an
article
that
shows me how I can do this in ASP.NET, C#?

Thanks
Danny
 
G

Guest

Hi Kevin

I tried what you said but get an error saying cannot implicitly convert type
Byte[] to string,
string body = encoding.GetBytes("Xml=" + HttpUtility.UrlEncode(XmlString));

I changed it the string body to byte [] and it worked fine when
Xml="sdfdsfsfsd", but when I put a "<" in the xml string an error occurs :
The remote server returned an error: (500) Internal Server Error.

Can you see what could be causing this?

Thanks
Danny



Kevin Spencer said:
Hi Danny,

If I understand you correctly, they are using a .Net program that employs
the HttpWebRequest to send the XML data via HTTP POST?

If so, you need to create an HTML form on the fly so to speak. This is not
too hard to do. An HTTP Post is a sequence of "name=value" pairs, separated
by '&' characters, just like a QueryString, but longer. The "name" part is
the name of a form field, and the "value" part is the data for that form
field. So, for example, if you wanted to POST a form having one field named
"foo" and the value in it was "bar" your body would simply look like this:

foo=bar

Of course, this must all be URLEncoded, and sending an XML document means a
lot of URLEncoding, for all the tags and such, but using URLEncode() will do
it. So, to send a single XML document via POST would be something like:

string body = "Xml=" + HttpUtility.URLEncode(XmlString);

"Xml" would be the name of the form field.

It has to be encoded into a byte array because you are actually sending a
stream, but it becomes a string at the other end. So, your code might look
something like the following:

ASCIIEncoding encoding = new ASCIIEncoding();
Stream requestStream = null;
string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest IoHttp = (HttpWebRequest) WebRequest.Create(lcUrl);
IoHttp.Method = "POST";
IoHttp.ContentType = "application/x-www-form-urlencoded";
string body = encoding.GetBytes("Xml=" + HttpUtility.URLEncode(XmlString));
IoHttp.ContentLength = body.Length;
try
{
requestStream = IoHttp.GetRequestStream();
requestStream.Write(body, 0, body.Length);
}
catch
{
//...
}
finally
{
if (requestStream != null) requestStream.Close();
}

In your ASPX page, you just get Request.Form["Xml"] which is already a
string.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

Danny said:
Thanks Kevin

To receive the byte array from the client should I be using
Request.InputStream ?

Assuming the method I think the clients will use to send the data to my
application, could be like this:

string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest loHttp =
(HttpWebRequest) WebRequest.Create(lcUrl);

// *** Send any POST data
string lcPostData =
"XMLData=" + HttpUtility.UrlEncode("xmldata..");

loHttp.Method="POST";
byte [] lbPostBuffer =
System.Text.Encoding.GetEncoding(1252).GetBytes(lcPostData);
loHttp.ContentLength = lbPostBuffer.Length;


Kevin Spencer said:
Convert the byte array to a string. Create an XmlDocument instance, and
use
the Load() method, passing the string to the constructor.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

I am working on a project where I will receive xml documents from
clients
machines as a byte array. They will use the web browser navigate method
to
post the data to my ASP.NET page. I then pick up the byte array using
the
request object (XMLData=bytearray..). Can someone point me to an
article
that
shows me how I can do this in ASP.NET, C#?

Thanks
Danny
 
K

Kevin Spencer

Hi Danny,

It doesn't matter what software the client is using. An HTTP message is an
HTTP message, and that is all that will arrive at the server. Good luck!

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a horse to water,
but you can't make him think.

Danny said:
Kevin thanks alot for your help. One quick question regarding this.
They will be using a .net program to post the xml data with the web
browser
method. Will this still work with what you said?

Regards
Danny


Kevin Spencer said:
Hi Danny,

If I understand you correctly, they are using a .Net program that employs
the HttpWebRequest to send the XML data via HTTP POST?

If so, you need to create an HTML form on the fly so to speak. This is
not
too hard to do. An HTTP Post is a sequence of "name=value" pairs,
separated
by '&' characters, just like a QueryString, but longer. The "name" part
is
the name of a form field, and the "value" part is the data for that form
field. So, for example, if you wanted to POST a form having one field
named
"foo" and the value in it was "bar" your body would simply look like
this:

foo=bar

Of course, this must all be URLEncoded, and sending an XML document means
a
lot of URLEncoding, for all the tags and such, but using URLEncode() will
do
it. So, to send a single XML document via POST would be something like:

string body = "Xml=" + HttpUtility.URLEncode(XmlString);

"Xml" would be the name of the form field.

It has to be encoded into a byte array because you are actually sending a
stream, but it becomes a string at the other end. So, your code might
look
something like the following:

ASCIIEncoding encoding = new ASCIIEncoding();
Stream requestStream = null;
string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest IoHttp = (HttpWebRequest) WebRequest.Create(lcUrl);
IoHttp.Method = "POST";
IoHttp.ContentType = "application/x-www-form-urlencoded";
string body = encoding.GetBytes("Xml=" +
HttpUtility.URLEncode(XmlString));
IoHttp.ContentLength = body.Length;
try
{
requestStream = IoHttp.GetRequestStream();
requestStream.Write(body, 0, body.Length);
}
catch
{
//...
}
finally
{
if (requestStream != null) requestStream.Close();
}

In your ASPX page, you just get Request.Form["Xml"] which is already a
string.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

Danny said:
Thanks Kevin

To receive the byte array from the client should I be using
Request.InputStream ?

Assuming the method I think the clients will use to send the data to my
application, could be like this:

string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest loHttp =
(HttpWebRequest) WebRequest.Create(lcUrl);

// *** Send any POST data
string lcPostData =
"XMLData=" + HttpUtility.UrlEncode("xmldata..");

loHttp.Method="POST";
byte [] lbPostBuffer =
System.Text.Encoding.GetEncoding(1252).GetBytes(lcPostData);
loHttp.ContentLength = lbPostBuffer.Length;


:

Convert the byte array to a string. Create an XmlDocument instance,
and
use
the Load() method, passing the string to the constructor.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

I am working on a project where I will receive xml documents from
clients
machines as a byte array. They will use the web browser navigate
method
to
post the data to my ASP.NET page. I then pick up the byte array
using
the
request object (XMLData=bytearray..). Can someone point me to an
article
that
shows me how I can do this in ASP.NET, C#?

Thanks
Danny
 
K

Kevin Spencer

My bad, Danny.

That should have read:

byte[] body = encoding.GetBytes("Xml=" + HttpUtility.UrlEncode(XmlString));

I was translating it from some software I've written before, and made a
mistake in the translation.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

Danny said:
Hi Kevin

I tried what you said but get an error saying cannot implicitly convert
type
Byte[] to string,
string body = encoding.GetBytes("Xml=" +
HttpUtility.UrlEncode(XmlString));

I changed it the string body to byte [] and it worked fine when
Xml="sdfdsfsfsd", but when I put a "<" in the xml string an error occurs :
The remote server returned an error: (500) Internal Server Error.

Can you see what could be causing this?

Thanks
Danny



Kevin Spencer said:
Hi Danny,

If I understand you correctly, they are using a .Net program that employs
the HttpWebRequest to send the XML data via HTTP POST?

If so, you need to create an HTML form on the fly so to speak. This is
not
too hard to do. An HTTP Post is a sequence of "name=value" pairs,
separated
by '&' characters, just like a QueryString, but longer. The "name" part
is
the name of a form field, and the "value" part is the data for that form
field. So, for example, if you wanted to POST a form having one field
named
"foo" and the value in it was "bar" your body would simply look like
this:

foo=bar

Of course, this must all be URLEncoded, and sending an XML document means
a
lot of URLEncoding, for all the tags and such, but using URLEncode() will
do
it. So, to send a single XML document via POST would be something like:

string body = "Xml=" + HttpUtility.URLEncode(XmlString);

"Xml" would be the name of the form field.

It has to be encoded into a byte array because you are actually sending a
stream, but it becomes a string at the other end. So, your code might
look
something like the following:

ASCIIEncoding encoding = new ASCIIEncoding();
Stream requestStream = null;
string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest IoHttp = (HttpWebRequest) WebRequest.Create(lcUrl);
IoHttp.Method = "POST";
IoHttp.ContentType = "application/x-www-form-urlencoded";
string body = encoding.GetBytes("Xml=" +
HttpUtility.URLEncode(XmlString));
IoHttp.ContentLength = body.Length;
try
{
requestStream = IoHttp.GetRequestStream();
requestStream.Write(body, 0, body.Length);
}
catch
{
//...
}
finally
{
if (requestStream != null) requestStream.Close();
}

In your ASPX page, you just get Request.Form["Xml"] which is already a
string.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

Danny said:
Thanks Kevin

To receive the byte array from the client should I be using
Request.InputStream ?

Assuming the method I think the clients will use to send the data to my
application, could be like this:

string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest loHttp =
(HttpWebRequest) WebRequest.Create(lcUrl);

// *** Send any POST data
string lcPostData =
"XMLData=" + HttpUtility.UrlEncode("xmldata..");

loHttp.Method="POST";
byte [] lbPostBuffer =
System.Text.Encoding.GetEncoding(1252).GetBytes(lcPostData);
loHttp.ContentLength = lbPostBuffer.Length;


:

Convert the byte array to a string. Create an XmlDocument instance,
and
use
the Load() method, passing the string to the constructor.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

I am working on a project where I will receive xml documents from
clients
machines as a byte array. They will use the web browser navigate
method
to
post the data to my ASP.NET page. I then pick up the byte array
using
the
request object (XMLData=bytearray..). Can someone point me to an
article
that
shows me how I can do this in ASP.NET, C#?

Thanks
Danny
 
G

Guest

Hi Kevin

When I put "<" character in the xml string the server that receives the xml
returns an error, (500) Internal Server Error.

Can you see what would cause this?

Thanks
Danny

Kevin Spencer said:
My bad, Danny.

That should have read:

byte[] body = encoding.GetBytes("Xml=" + HttpUtility.UrlEncode(XmlString));

I was translating it from some software I've written before, and made a
mistake in the translation.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

Danny said:
Hi Kevin

I tried what you said but get an error saying cannot implicitly convert
type
Byte[] to string,
string body = encoding.GetBytes("Xml=" +
HttpUtility.UrlEncode(XmlString));

I changed it the string body to byte [] and it worked fine when
Xml="sdfdsfsfsd", but when I put a "<" in the xml string an error occurs :
The remote server returned an error: (500) Internal Server Error.

Can you see what could be causing this?

Thanks
Danny



Kevin Spencer said:
Hi Danny,

If I understand you correctly, they are using a .Net program that employs
the HttpWebRequest to send the XML data via HTTP POST?

If so, you need to create an HTML form on the fly so to speak. This is
not
too hard to do. An HTTP Post is a sequence of "name=value" pairs,
separated
by '&' characters, just like a QueryString, but longer. The "name" part
is
the name of a form field, and the "value" part is the data for that form
field. So, for example, if you wanted to POST a form having one field
named
"foo" and the value in it was "bar" your body would simply look like
this:

foo=bar

Of course, this must all be URLEncoded, and sending an XML document means
a
lot of URLEncoding, for all the tags and such, but using URLEncode() will
do
it. So, to send a single XML document via POST would be something like:

string body = "Xml=" + HttpUtility.URLEncode(XmlString);

"Xml" would be the name of the form field.

It has to be encoded into a byte array because you are actually sending a
stream, but it becomes a string at the other end. So, your code might
look
something like the following:

ASCIIEncoding encoding = new ASCIIEncoding();
Stream requestStream = null;
string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest IoHttp = (HttpWebRequest) WebRequest.Create(lcUrl);
IoHttp.Method = "POST";
IoHttp.ContentType = "application/x-www-form-urlencoded";
string body = encoding.GetBytes("Xml=" +
HttpUtility.URLEncode(XmlString));
IoHttp.ContentLength = body.Length;
try
{
requestStream = IoHttp.GetRequestStream();
requestStream.Write(body, 0, body.Length);
}
catch
{
//...
}
finally
{
if (requestStream != null) requestStream.Close();
}

In your ASPX page, you just get Request.Form["Xml"] which is already a
string.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

Thanks Kevin

To receive the byte array from the client should I be using
Request.InputStream ?

Assuming the method I think the clients will use to send the data to my
application, could be like this:

string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest loHttp =
(HttpWebRequest) WebRequest.Create(lcUrl);

// *** Send any POST data
string lcPostData =
"XMLData=" + HttpUtility.UrlEncode("xmldata..");

loHttp.Method="POST";
byte [] lbPostBuffer =
System.Text.Encoding.GetEncoding(1252).GetBytes(lcPostData);
loHttp.ContentLength = lbPostBuffer.Length;


:

Convert the byte array to a string. Create an XmlDocument instance,
and
use
the Load() method, passing the string to the constructor.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

I am working on a project where I will receive xml documents from
clients
machines as a byte array. They will use the web browser navigate
method
to
post the data to my ASP.NET page. I then pick up the byte array
using
the
request object (XMLData=bytearray..). Can someone point me to an
article
that
shows me how I can do this in ASP.NET, C#?

Thanks
Danny
 
K

Kevin Spencer

I don't really know anything about how you're processing it at the server
end.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

Danny said:
Hi Kevin

When I put "<" character in the xml string the server that receives the
xml
returns an error, (500) Internal Server Error.

Can you see what would cause this?

Thanks
Danny

Kevin Spencer said:
My bad, Danny.

That should have read:

byte[] body = encoding.GetBytes("Xml=" +
HttpUtility.UrlEncode(XmlString));

I was translating it from some software I've written before, and made a
mistake in the translation.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

Danny said:
Hi Kevin

I tried what you said but get an error saying cannot implicitly convert
type
Byte[] to string,
string body = encoding.GetBytes("Xml=" +
HttpUtility.UrlEncode(XmlString));

I changed it the string body to byte [] and it worked fine when
Xml="sdfdsfsfsd", but when I put a "<" in the xml string an error
occurs :
The remote server returned an error: (500) Internal Server Error.

Can you see what could be causing this?

Thanks
Danny



:

Hi Danny,

If I understand you correctly, they are using a .Net program that
employs
the HttpWebRequest to send the XML data via HTTP POST?

If so, you need to create an HTML form on the fly so to speak. This is
not
too hard to do. An HTTP Post is a sequence of "name=value" pairs,
separated
by '&' characters, just like a QueryString, but longer. The "name"
part
is
the name of a form field, and the "value" part is the data for that
form
field. So, for example, if you wanted to POST a form having one field
named
"foo" and the value in it was "bar" your body would simply look like
this:

foo=bar

Of course, this must all be URLEncoded, and sending an XML document
means
a
lot of URLEncoding, for all the tags and such, but using URLEncode()
will
do
it. So, to send a single XML document via POST would be something
like:

string body = "Xml=" + HttpUtility.URLEncode(XmlString);

"Xml" would be the name of the form field.

It has to be encoded into a byte array because you are actually
sending a
stream, but it becomes a string at the other end. So, your code might
look
something like the following:

ASCIIEncoding encoding = new ASCIIEncoding();
Stream requestStream = null;
string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest IoHttp = (HttpWebRequest) WebRequest.Create(lcUrl);
IoHttp.Method = "POST";
IoHttp.ContentType = "application/x-www-form-urlencoded";
string body = encoding.GetBytes("Xml=" +
HttpUtility.URLEncode(XmlString));
IoHttp.ContentLength = body.Length;
try
{
requestStream = IoHttp.GetRequestStream();
requestStream.Write(body, 0, body.Length);
}
catch
{
//...
}
finally
{
if (requestStream != null) requestStream.Close();
}

In your ASPX page, you just get Request.Form["Xml"] which is already a
string.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

Thanks Kevin

To receive the byte array from the client should I be using
Request.InputStream ?

Assuming the method I think the clients will use to send the data to
my
application, could be like this:

string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest loHttp =
(HttpWebRequest) WebRequest.Create(lcUrl);

// *** Send any POST data
string lcPostData =
"XMLData=" + HttpUtility.UrlEncode("xmldata..");

loHttp.Method="POST";
byte [] lbPostBuffer =
System.Text.Encoding.GetEncoding(1252).GetBytes(lcPostData);
loHttp.ContentLength = lbPostBuffer.Length;


:

Convert the byte array to a string. Create an XmlDocument instance,
and
use
the Load() method, passing the string to the constructor.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

I am working on a project where I will receive xml documents from
clients
machines as a byte array. They will use the web browser navigate
method
to
post the data to my ASP.NET page. I then pick up the byte array
using
the
request object (XMLData=bytearray..). Can someone point me to an
article
that
shows me how I can do this in ASP.NET, C#?

Thanks
Danny
 
G

Guest

Basically I have an ASP.NET page, in the PAGE_LOAD event I have:
//Response.Write (Request.Form["XMLData"]);
I would assume this would be returned to the client application.

Thanks
Danny

Kevin Spencer said:
I don't really know anything about how you're processing it at the server
end.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

Danny said:
Hi Kevin

When I put "<" character in the xml string the server that receives the
xml
returns an error, (500) Internal Server Error.

Can you see what would cause this?

Thanks
Danny

Kevin Spencer said:
My bad, Danny.

That should have read:

byte[] body = encoding.GetBytes("Xml=" +
HttpUtility.UrlEncode(XmlString));

I was translating it from some software I've written before, and made a
mistake in the translation.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

Hi Kevin

I tried what you said but get an error saying cannot implicitly convert
type
Byte[] to string,
string body = encoding.GetBytes("Xml=" +
HttpUtility.UrlEncode(XmlString));

I changed it the string body to byte [] and it worked fine when
Xml="sdfdsfsfsd", but when I put a "<" in the xml string an error
occurs :
The remote server returned an error: (500) Internal Server Error.

Can you see what could be causing this?

Thanks
Danny



:

Hi Danny,

If I understand you correctly, they are using a .Net program that
employs
the HttpWebRequest to send the XML data via HTTP POST?

If so, you need to create an HTML form on the fly so to speak. This is
not
too hard to do. An HTTP Post is a sequence of "name=value" pairs,
separated
by '&' characters, just like a QueryString, but longer. The "name"
part
is
the name of a form field, and the "value" part is the data for that
form
field. So, for example, if you wanted to POST a form having one field
named
"foo" and the value in it was "bar" your body would simply look like
this:

foo=bar

Of course, this must all be URLEncoded, and sending an XML document
means
a
lot of URLEncoding, for all the tags and such, but using URLEncode()
will
do
it. So, to send a single XML document via POST would be something
like:

string body = "Xml=" + HttpUtility.URLEncode(XmlString);

"Xml" would be the name of the form field.

It has to be encoded into a byte array because you are actually
sending a
stream, but it becomes a string at the other end. So, your code might
look
something like the following:

ASCIIEncoding encoding = new ASCIIEncoding();
Stream requestStream = null;
string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest IoHttp = (HttpWebRequest) WebRequest.Create(lcUrl);
IoHttp.Method = "POST";
IoHttp.ContentType = "application/x-www-form-urlencoded";
string body = encoding.GetBytes("Xml=" +
HttpUtility.URLEncode(XmlString));
IoHttp.ContentLength = body.Length;
try
{
requestStream = IoHttp.GetRequestStream();
requestStream.Write(body, 0, body.Length);
}
catch
{
//...
}
finally
{
if (requestStream != null) requestStream.Close();
}

In your ASPX page, you just get Request.Form["Xml"] which is already a
string.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

Thanks Kevin

To receive the byte array from the client should I be using
Request.InputStream ?

Assuming the method I think the clients will use to send the data to
my
application, could be like this:

string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest loHttp =
(HttpWebRequest) WebRequest.Create(lcUrl);

// *** Send any POST data
string lcPostData =
"XMLData=" + HttpUtility.UrlEncode("xmldata..");

loHttp.Method="POST";
byte [] lbPostBuffer =
System.Text.Encoding.GetEncoding(1252).GetBytes(lcPostData);
loHttp.ContentLength = lbPostBuffer.Length;


:

Convert the byte array to a string. Create an XmlDocument instance,
and
use
the Load() method, passing the string to the constructor.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

I am working on a project where I will receive xml documents from
clients
machines as a byte array. They will use the web browser navigate
method
to
post the data to my ASP.NET page. I then pick up the byte array
using
the
request object (XMLData=bytearray..). Can someone point me to an
article
that
shows me how I can do this in ASP.NET, C#?

Thanks
Danny
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top