小编New*_*ary的帖子

dataStream.Length和.Position抛出类型为'System.NotSupportedException'的异常

我试图使用http post从asp.net发布一些数据到webservice.

这样做我得到了封闭的错误.我检查过很多帖子,但没有什么可以帮助我.对此的任何帮助将非常感谢.

Length ='dataStream.Length'引发了类型'System.NotSupportedException'的异常

Position ='dataStream.Position'引发了类型'System.NotSupportedException'的异常

随函附上我的代码:

public XmlDocument SendRequest(string command, string request)
{
    XmlDocument result = null;

    if (IsInitialized())
    {
        result = new XmlDocument();

        HttpWebRequest webRequest = null;
        HttpWebResponse webResponse = null;

        try
        {
            string prefix = (m_SecureMode) ? "https://" : "http://";
            string url = string.Concat(prefix, m_Url, command);

            webRequest = (HttpWebRequest)WebRequest.Create(url);
            webRequest.Method = "POST";
            webRequest.ContentType = "text/xml";
            webRequest.ServicePoint.Expect100Continue = false;

            string UsernameAndPassword = string.Concat(m_Username, ":", m_Password);
            string EncryptedDetails = Convert.ToBase64String(Encoding.ASCII.GetBytes(UsernameAndPassword));

            webRequest.Headers.Add("Authorization", "Basic " + EncryptedDetails);

            using (StreamWriter sw …
Run Code Online (Sandbox Code Playgroud)

c# asp.net post

5
推荐指数
1
解决办法
3万
查看次数

流异常和System.Xml.XmlException:' - '是一个意外的标记.预期的令牌是''

我收到StreamWriter抛出的错误,我收到的消息是:

Length = '(sw.BaseStream).Length' threw an exception of type 'System.NotSupportedException'
Position = '(sw.BaseStream).Position' threw an exception of type 'System.NotSupportedException'
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪:

Message: System.Xml.XmlException: '6163592' is an unexpected token. The expected token is '\'" or "".
Stack Trace: System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
   at System.Xml.XmlTextReaderImpl.ThrowUnexpectedToken(String expectedToken1, String expectedToken2)
   at System.Xml.XmlTextReaderImpl.ParseAttributes()
   at System.Xml.XmlTextReaderImpl.ParseElement()
   at System.Xml.XmlTextReaderImpl.ParseElementContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)
   at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
   at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
   at System.Xml.XmlDocument.Load(XmlReader reader)
   at System.Xml.XmlDocument.Load(Stream inStream)
   at BasecampManager.SendRequest(String command, String request) …
Run Code Online (Sandbox Code Playgroud)

c# xml streamwriter

0
推荐指数
1
解决办法
2413
查看次数

标签 统计

c# ×2

asp.net ×1

post ×1

streamwriter ×1

xml ×1