Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# xml通过post发送到ashx处理程序。某些字符作为“quot;?”发送&引用;,解决不了_C#_Xml_Vb.net_Encoding_Ashx - Fatal编程技术网

C# xml通过post发送到ashx处理程序。某些字符作为“quot;?”发送&引用;,解决不了

C# xml通过post发送到ashx处理程序。某些字符作为“quot;?”发送&引用;,解决不了,c#,xml,vb.net,encoding,ashx,C#,Xml,Vb.net,Encoding,Ashx,大家好,复活节快乐 我有两个处理程序,一个外部处理程序和一个内部处理程序是用vb.net编写的。 我使用c#编写的测试程序将xml发送到外部处理程序,外部处理程序将xml发送到内部处理程序,这样我就可以将xml存储到数据库中 c语言中的测试类代码# 我正在读取一个xml,并使用请求-响应通过post将其发送到url FileStream READER=newfilestream(“C:/Users/pantoniou.MAGR/Desktop/quote.xml”,FileMode.Open,F

大家好,复活节快乐

我有两个处理程序,一个外部处理程序和一个内部处理程序是用vb.net编写的。 我使用c#编写的测试程序将xml发送到外部处理程序,外部处理程序将xml发送到内部处理程序,这样我就可以将xml存储到数据库中

c语言中的测试类代码# 我正在读取一个xml,并使用请求-响应通过post将其发送到url

FileStream READER=newfilestream(“C:/Users/pantoniou.MAGR/Desktop/quote.xml”,FileMode.Open,FileAccess.Read,FileShare.ReadWrite)//设置文件流(读卡器)//
XmlDocument doc=新的XmlDocument();
文件加载(读卡器);
字符串xmlcontents=doc.InnerXml;
//WebRequest WebRequest=WebRequest.Create(新Uri(“http://172.30.28.41/allianzservice/Handler1.ashx"));

外部服务代码 在这里,我第一次获得xml,并通过post将其传递给内部处理程序

Dim stream=context.Request.InputStream
作为字节()的Dim缓冲区=新字节(stream.Length-1){}
stream.Read(buffer,0,buffer.Length)
Dim xml As String=Encoding.UTF8.GetString(缓冲区)

和内部处理程序代码

这里我获取xml并将其反序列化为一个对象

Dim stream=context.Request.InputStream
作为字节()的Dim缓冲区=新字节(stream.Length-1){}
stream.Read(buffer,0,buffer.Length)
Dim xml As String=Encoding.UTF8.GetString(缓冲区)

所以问题是,正如我之前所写的,在数据库中,大多数值都是ok的 有些值存储为问号“?”

我试过在编码上乱搞,但没有任何帮助。 我知道问题是在通过处理程序发送xml时发生的。 我尝试直接从内部处理程序读取xml,并将其转换为对象,然后将其存储到数据库中,一切正常

当我通过处理程序发送xml并在某些值中获取“?”时,会发生一些事情


谢谢你的帮助

您似乎在以ASCII模式从文件中读取字节

byte[] bytes = Encoding.ASCII.GetBytes(xmlcontents); 
将此更改为

byte[] bytes = Encoding.Default.GetBytes(xmlcontents);


因为你们只是想上传文件,我建议你们使用这个方法

试一试


我试过了,当我将其更改为utf-8或默认值时,我得到一个错误500作为响应,无法将任何内容存储到数据库中。您也没有创建正确的帖子边界,通常在上载文件时,它使用多部分帖子格式,我看不到任何类似的错误,这就是错误500的原因!你能详细说明一下吗?读这个!
    context.Response.Write(xml)

    'Dim READER As New FileStream("C:/Users/pantoniou.MAGR/Desktop/quote.xml", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)

    Dim doc As New XmlDocument()
    doc.LoadXml(xml)

    Dim xmlcontents As String = doc.InnerXml

    Dim wrapper As [Interface]
    Dim ser = New XmlSerializer(GetType([Interface]), New XmlRootAttribute("interface"))
    Dim reader1 As New StringReader(xmlcontents)
    wrapper = DirectCast(ser.Deserialize(reader1), [Interface])`
byte[] bytes = Encoding.ASCII.GetBytes(xmlcontents); 
byte[] bytes = Encoding.Default.GetBytes(xmlcontents);
byte[] bytes = Encoding.UTF8.GetBytes(xmlcontents);
var client = new WebClient();
byte[] response = client.UploadFile("http://172.30.29.2/allianzhttpouter/Handler1.ashx", "PATH TO UR XML");