字节数组问题 [英] byte array problem

查看:77
本文介绍了字节数组问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个项目,我将从客户端收到xml文件

机器作为字节数组。他们将使用Web浏览器导航方法将数据发布到我的ASP.NET页面。
。然后我使用

请求对象(XMLData = bytearray ..)获取字节数组。有人能指点我一篇文章

告诉我如何在ASP.NET中做到这一点,C#?


谢谢

Danny

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

推荐答案

将字节数组转换为字符串。创建一个XmlDocument实例,并使用

Load()方法,将字符串传递给构造函数。


-

HTH,


Kevin Spencer

Microsoft MVP

..Net开发人员

如果你推送一些东西很难,

它会摔倒。

- Fudd'的第一反对法


Danny <沓*** @ discussions.microsoft.com>在留言中写道

news:97 ********************************** @ microsof t.com ...
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

"Danny" <Da***@discussions.microsoft.com> wrote in message
news:97**********************************@microsof t.com...
我正在开发一个项目,我将从客户端机器接收xml文档作为字节数组。他们将使用Web浏览器导航方法将数据发布到我的ASP.NET页面。然后我使用
请求对象(XMLData = bytearray ..)获取字节数组。有人能指点我一篇文章

告诉我如何在ASP.NET中做到这一点,C#?

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



谢谢Kevin


要从客户端接收字节数组我应该使用

Request.InputStream ?


假设我认为客户将用于将数据发送到我的

应用程序的方法可能是这样的:

string lcUrl =" http://localhost/test/receive.aspx" ;;

HttpWebRequest loHttp =

(HttpWebRequest)WebRequest.Create(lcUrl );


// ***发送任何POST数据

string lcPostData =

" XMLData =" + HttpUtility.UrlEncode(" xmldata ..");


loHttp.Method =" POST";

byte [] lbPostBuffer =

System.Text.Encoding.GetEncoding(1252).GetBytes(lc PostData);

loHttp.ContentLength = lbPostBuffer.Length;

" Kevin斯潘塞"写道:
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(lc PostData);
loHttp.ContentLength = lbPostBuffer.Length;
"Kevin Spencer" wrote:
将字节数组转换为字符串。创建一个XmlDocument实例,并使用
Load()方法,将字符串传递给构造函数。

-
HTH,

Kevin Spencer
微软MVP
..Net开发人员
如果你足够努力,
它将会失败。
- Fudd'的第一反对法
丹尼 <沓*** @ discussions.microsoft.com>在消息中写道
新闻:97 ********************************** @ microsof t.com。 ..
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

"Danny" <Da***@discussions.microsoft.com> wrote in message
news:97**********************************@microsof t.com...
我正在开展一个项目,我将从客户机器接收xml文件作为字节数组。他们将使用Web浏览器导航方法将数据发布到我的ASP.NET页面。然后我使用
请求对象(XMLData = bytearray ..)获取字节数组。有人能指点我一篇文章

告诉我如何在ASP.NET中做到这一点,C#?

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




嗨Danny,

如果我理解正确,他们正在使用.Net程序使用

HttpWebRequest通过HTTP POST发送XML数据?


如果是这样,你需要动态创建一个HTML表单。这不是很难做到的。 HTTP Post是name = value的序列。对,用''&''字符分隔

,就像QueryString一样,但更长。 名称部分是

表单字段的名称,以及值。 part是该表格的数据

字段。因此,例如,如果您想POST一个名为

" foo"的字段的表单。其中的值是bar。你的身体看起来就像这样:


foo = bar


当然,这必须都是URLEncoded,发送XML文件意味着对于所有的标签等,很多URLEncoding都会花费很多,但是使用URLEncode()会做到这一点。/ b
吧。因此,通过POST发送单个XML文档将类似于:

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


" Xml"将是表单字段的名称。


必须将其编码为字节数组,因为您实际上是在发送一个

流,但它变成了字符串在另一端。因此,您的代码可能看起来如下所示:


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

{

// ...

}

终于

{

if(requestStream!= null)requestStream.Close();

}


在ASPX页面中,您只需获得已读的Request.Form [" Xml"]呀

string。


-

HTH,


Kevin Spencer

Microsoft MVP

..Net开发人员

如果你推得足够的东西,

它会倒下。< br $> b $ b - Fudd的第一反对法


Danny <沓*** @ discussions.microsoft.com>在留言中写道

新闻:A5 ********************************** @ microsof t.com ...
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" <Da***@discussions.microsoft.com> wrote in message
news:A5**********************************@microsof t.com...
谢谢Kevin

要从客户端接收字节数组我应该使用
Request.InputStream吗?
应用程序的方法可能是这样的:

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

// ***发送任何POST数据
string lcPostData =
XMLData = + HttpUtility.UrlEncode(" xmldata ..");

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

" Kevin Spencer"写道:
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(lc PostData);
loHttp.ContentLength = lbPostBuffer.Length;
"Kevin Spencer" wrote:
将字节数组转换为字符串。创建一个XmlDocument实例,并使用
Load()方法,将字符串传递给构造函数。

-
HTH,
微软MVP
..Net开发人员
如果你足够努力,
它将会失败。
- Fudd的第一定律反对派

丹尼 <沓*** @ discussions.microsoft.com>在消息中写道
新闻:97 ********************************** @ microsof t.com。 ..
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

"Danny" <Da***@discussions.microsoft.com> wrote in message
news:97**********************************@microsof t.com...
>我正在开展一个项目,我将从
>客户获得xml文件
>机器作为字节数组。他们将使用网页浏览器导航方法
>到
>将数据发布到我的ASP.NET页面。然后我使用
>获取字节数组。
>请求对象(XMLData = bytearray ..)。有人能指点我
>文章
>
>向我展示了如何在ASP.NET中实现这一点,C#?
>
>谢谢
> Danny
>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




这篇关于字节数组问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆