开发者

"Post" XML Data like HTML with Hidden Values using ContentType ="txt/html"

开发者 https://www.devze.com 2022-12-21 02:05 出处:网络
I want to do the same that works previously on HTML but now via .NET Windows Forms. When I submit this HTML it works :

I want to do the same that works previously on HTML but now via .NET Windows Forms.

When I submit this HTML it works :

<html>
<head>
</head>
<body> 
<form name="TestForm" action="http://staging.csatravelprotection.com/ws/policyrequest" method="POST">
<input type="hidden" name="xmlrequeststring" value=" 
<quoterequest>
  <aff>COSTAMAR</aff> <!-- required -->
  <producer>10527930</producer> <!-- optional -->
  开发者_C百科<productclass>85FL</productclass>  <!-- required -->
  <bookingreservno>0123456789AB</bookingreservno>  <!-- optional -->
  <numinsured>3</numinsured>  <!-- required -->
  <tripcost>5000.00</tripcost>  <!-- required -->
  <departdate>2010-11-01</departdate>  <!-- required -->
  <returndate>2010-11-20</returndate>  <!-- required -->
  <triptype>Cruise</triptype> <!-- optional -->
  <destination>Europe/ Mediterranean</destination>  <!-- required -->
  <supplier>Carnival Cruise Lines</supplier>  <!-- optional -->
  <airline>American</airline>  <!-- optional-->
  <travelers>
    <traveler>
      <age>45</age>  <!-- required -->
    </traveler>
    <traveler>
      <age>43</age>  <!-- required -->
    </traveler>
    <traveler>
      <age>15</age>  <!-- required -->
    </traveler>
  </travelers>
</quoterequest> 
">

<input type="submit" name="submit" value="submit">
</form> 
</body>
</html>

but when I try to send the XML via POST using .NET it appear to fail cause I dont know how to post via Hidden Input on the URI.

Imports System.IO
Imports System.Text
Imports System.Net
Public Class Form2
    Private Shared URL As String = "http://staging.csatravelprotection.com/ws/policyrequest"
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim oHttpWebRequest As WebRequest = WebRequest.Create(New Uri(URL))
        oHttpWebRequest.Method = "POST"
        oHttpWebRequest.ContentType = "text/xml"
        Dim oStream As Stream = oHttpWebRequest.GetRequestStream()
        Dim Reader As StreamReader = New StreamReader("C:\TEST.XML", Encoding.Default)
        Dim Postdata As String = String.Format("xmlrequeststring={0}", Reader.ReadToEnd)
        oStream.Write(Encoding.ASCII.GetBytes(Postdata), 0, Postdata.Length)
        oStream.Close()
        Dim oHttpWebResponse As HttpWebResponse = CType(oHttpWebRequest.GetResponse(), HttpWebResponse)
        Dim oStreamResponse As Stream = oHttpWebResponse.GetResponseStream()
        Dim oStreamRead As StreamReader = New StreamReader(oStreamResponse, Encoding.UTF8)
        Dim strReturnedXML As String = oStreamRead.ReadToEnd()

        MessageBox.Show(strReturnedXML)
        oStreamResponse.Close()
        oStreamRead.Close()
        oHttpWebResponse.Close()
    End Sub
End Class

XML :

<quoterequest>
  <aff>COSTAMAR</aff> 
  <producer>10527930</producer>
  <productclass>TBD</productclass>
  <bookingreservno>0123456789AB</bookingreservno> 
  <numinsured>3</numinsured>  
  <tripcost>5000.00</tripcost> 
  <departdate>2009-11-01</departdate>
  <returndate>2009-11-20</returndate>
  <initdate>2008-09-30</initdate>
  <finalpaymentdate>2008-10-30</finalpaymentdate> 
  <triptype>Cruise</triptype>
  <destination>Europe/ Mediterranean</destination> 
  <supplier>Carnival Cruise Lines</supplier>
  <airline>American</airline>
</quoterequest>

Is there a way to make it work as expected on .NET?

Thanks


It is possible, but you should not post only the xml data, but the original html file with your xml data embedded. Het recieving page expects the data in that form. It cannot/does not see the difference between a browser or your program posting.

It could be that they have a different url form posting xml format data.

MarcelDevG


Thats impossible, but you can work with POST using ContentType ="txt/xml"

0

精彩评论

暂无评论...
验证码 换一张
取 消