Hi,
I have a problem with getting data from aplication server which is
behaving like web server.
I need to send there some xml query and I should receive another xml
response.
The aplication server trusts only these queries that have in head of
the protocol the valid user name and password.
//The head of HTTP protocol should look like:
POST /Index.aspx HTTP/1.1
Authorization: Basic ah21lbm6aGVbHRr8=
Content-Length: 7
//And the xml POST text like:
<ping/>
//I should get something like that:
HTTP/1.1 200 OK
Server: mooa
Content-Type: XML
Content-Length: 105
<?xml version="1.0"?>
<result ver="1">
<error>0</error>
<pong/>
</result>
But in the end I got only Html code of the Index.aspx page.
Could anyone help me please?
Jitsu
Imports System
Imports System.Security
Imports System.Security.Cryptography.X509Certificates
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.Net
Imports System.Net.WebClient
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
System.Net.ServicePointManager.CertificatePolicy = New
AcceptAllCertificatePolicy
Dim userString As String = "UserName"
Dim passwString As String = "Password123"
Dim userpaswString As String = userString & ":" & passwString
Dim queryString As String = "<ping/>"
Dim AuthBytes As Byte() =
System.Text.Encoding.ASCII.GetBytes(userpaswString )
Dim headerString As String = Convert.ToBase64String(AuthBytes)
'Load the certificate from a file
Dim cert As X509Certificate2 = New X509Certificate2("C:
\cert.pfx", "CertPassw123")
Dim request As HttpWebRequest = ttpWebRequest.Create("https://
extranet.mooa.com:8225")
request.ClientCertificates.Add(cert)
request.Method = "POST"
request.ContentType = "text/xml"
request.Headers.Add("Authorization: Basic " & headerString)
request.Timeout = 10000
'write data to request
Dim reqPostBuffer As Byte() =
System.Text.Encoding.UTF8.GetBytes(queryString)
request.ContentLength = reqPostBuffer.Length
Dim reqPostData As Stream = request.GetRequestStream()
reqPostData.Write(reqPostBuffer, 0, reqPostBuffer.Length)
reqPostData.Close()
Dim reqWebResponse As HttpWebResponse = request.GetResponse()
Dim enc As Encoding = System.Text.Encoding.UTF8
Dim reqResponseStream As StreamReader = New
reamReader(reqWebResponse.GetResponseStream(), enc)
Dim resHtml As String = reqResponseStream.ReadToEnd()
Debug.Print(resHtml)
reqWebResponse.Close()
reqResponseStream.Close()
End Sub
Private Class AcceptAllCertificatePolicy
Implements System.Net.ICertificatePolicy
Public Function CheckValidationResult(ByVal srvPoint As
System.Net.ServicePoint, ByVal certificate As
System.Security.Cryptography.X509Certificates.X509 Certificate, ByVal
request As System.Net.WebRequest, ByVal certificateProblem As Integer)
As Boolean Implements
System.Net.ICertificatePolicy.CheckValidationResul t
Return True
End Function
End Class
End Class