?
Solved

XmlDocument protocol violation

Posted on 2006-07-17
2
Medium Priority
?
461 Views
Last Modified: 2008-02-01
Having problems translating VB6 to VB.NET (Visual Studio 2005)
Error: "The server committed a protocol violation"
Tried it with 2 different URL's same as in original code.
One works, the other doesn't.
For security reasons I can't give the exact URL but this is what the failed URL looks like:
http://notwww.someprovider.com/long_security_key/sub_folder/page_without_extension?FORMAT=XML&PARM1=0%23.AA.BB
The succesful URL only differs in page_without_extension and parameters, the key and such are the same.
innerText and innerXML is filled with sensible data for the succesful page.
When I try the bad URL in IE, firefox or VB6 it does work.

VB6


Set m_xmlChain = New DOMDocument30
m_xmlChain.resolveExternals = False
m_xmlChain.validateOnParse = False
m_xmlChain.async = True
m_Done = False
m_xmlChain.Load URLSTRING
While Not m_Done
    DoEvents
Wend

Private Sub m_xmlChain_onreadystatechange()
  If m_xmlChain.readyState = 4 Then
    m_Done = True
  End If
End Sub



VB.NET


m_xmlChain = New XmlDocument
       'm_xmlChain.resolveExternals = False   ' my attempt to translate this line is in next 3 lines
Dim resolver As New XmlUrlResolver()
resolver.Credentials = CredentialCache.DefaultCredentials
m_xmlChain.XmlResolver = resolver
       'm_xmlChain.validateOnParse = False   ' how to translate?
       'm_xmlChain.async = True                   ' how to translate?
Try
      m_xmlChain.Load(URLSTRING)
Catch ex As Exception
      messagebox.show(ex.tostring)
End Try

Any comments and improvements to the code are welcome, I'm new to this XML stuff in VB.NET. Only played a little with it in javascript.


Follow up Q:
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21921874.html

Kind regards,

Nico
0
Comment
Question by:NicoLaan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
Loial earned 2000 total points
ID: 17130087
This might be caused by a badly formed result page, i.e. no crlf but only cr or only lf.
If so it can be solved by placing the following in the config file for your project.

  <system.net>
    <settings>
      <httpWebRequest useUnsafeHeaderParsing = "true" />
    </settings>
  </system.net>

See also for security implications:
http://msdn2.microsoft.com/en-us/library/system.net.configuration.httpwebrequestelement.useunsafeheaderparsing.aspx

Quote from that page:

Remarks

When this property is set to false, the following validations are performed during HTTP parsing:
    *      In end-of-line code, use CRLF; using CR or LF alone is not allowed.
    *      Headers names should not have spaces in them.
    *      If multiple status lines exist, all additional status lines are treated as malformed header name/value pairs.
    *      The status line must have a status description, in addition to a status code.
    *      Header names cannot have non-ASCII chars in them. This validation is performed whether this property is set to true or false.
When a protocol violation occurs, a WebException exception is thrown with the status set to ServerProtocolViolation. If the UseUnsafeHeaderParsing property is set to true, validation errors are ignored.

Setting this property to true has security implications, so it should only be done if backward compatibility with a server is required.
0
 
LVL 4

Author Comment

by:NicoLaan
ID: 17130213
That's it, it works!
It was the crlf you mentioned. The xml only had 0A my hexeditor told me.
Thanks a lot!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question