473,403 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

HttpWebRequest - problem with Authorization

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

May 30 '07 #1
0 1146

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Satinderpal Singh | last post by:
Hi everyone, We are using HttpWebRequest to create a request to a URI, which requires us to login first. In order to process all the transactions, first we have to login and get the cookie value...
0
by: Abhimanyu Sirohi | last post by:
Hi, While trying to access a document on my server through my C# application ,it says "Remote Server returned and Error : 401 Unauthorised" but when i access it thro Internet Explorer it works...
3
by: superseed | last post by:
Hi, I'm currently coding in C# a class to control a PTZ (Pan Tilt Zoom) Camera. To control the camera I have to send request on a CGI on it. Something like this : ...
15
by: warlord | last post by:
I have a windows client app that is trying to download a file from a web server but I always get the following error when I call the GetResponse method of the Request object. The remote server...
1
by: Satinderpal Singh | last post by:
Hi everyone, We are using HttpWebRequest to create a request to a URI, which requires us to login first. In order to process all the transactions, first we have to login and get the cookie value...
2
by: Michael | last post by:
Hi all.. I need to submit an asynchronous request for a credit card authorization. I have an aspx page where the user confirms the transaction and clicks a button to send the transaction to the...
8
by: Noel Volin | last post by:
Anyone who can help here is much appreciated. I am trying to programmatically log onto a website. I am using the code provided in VS for the AuthenticationManager Class example (...
1
by: phil.jacobs | last post by:
Hi there, I am very stuck and have tried everything on this one! I am trying to get to an https website and cannot work out how to logon. When I log on manually, I have to enter username and...
0
by: jitsu | last post by:
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...
8
by: gerbrandc | last post by:
Hello, I hope somebody has a good explanation for this issue. Okay I'm having troubles with the httpWebRequest method. I need to download reports from a specified server (can't give these...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.