Dim myCred As New NetworkCredential("USERNAME", "PASSWORD")
Dim credsCache As New CredentialCache()
credsCache.Add(New Uri(Uri), "Basic", myCred)
Dim request As WebRequest = WebRequest.Create(Uri)
request.Credentials = credsCache
Dim request As WebRequest
Dim credidentials As String = "userName" + ":" + "Password"
Authorization = Convert.ToBase64String(Encoding.[Default].GetBytes(credidentials)) 'How do I declare Authorization?
request.Headers("Authorization") = "Basic " + Authorization
Imports System.Net
Imports System.Text
Module Module1
Sub Main()
Dim username As String = "username"
Dim password As String = "passwort"
Dim url As String = "http://your.url"
Dim credentials As String = Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password))
Dim webClient As WebClient = New WebClient()
webClient.Headers(HttpRequestHeader.Authorization) = "Basic " + credentials
webClient.UploadString(url, "your string")
Console.WriteLine("Done.")
Console.ReadLine()
End Sub
End Module
Private Sub PostXMLfile(ByVal x As String, ByRef WebString As String)
Dim username As String = "username"
Dim password As String = "password"
Dim request As HttpWebRequest
Dim response As HttpWebResponse = Nothing
Dim reader As StreamReader
Dim xmlDocAsStr As String = x
Dim byteArray(xmlDocAsStr.Length - 1) As Byte
Dim objUTF8Encoding As New UTF8Encoding
Dim Uri As String = "https://test.com/invoke/B2BShipmentDeliveryStatus.externalCarriers.services:receiveConfirmation"
Dim postStream As Stream = Nothing
'Some code from: https://developer.yahoo.com/dotnet/howto-rest_vb.html
'
Try
' Create the web request
request = DirectCast(WebRequest.Create(Uri), HttpWebRequest)
byteArray = objUTF8Encoding.GetBytes(xmlDocAsStr)
request.Method = "POST"
request.ContentLength = byteArray.Length
request.ContentType = "text/xml"
' Add authentication to request
request.Credentials = New NetworkCredential(username, password)
'
Try
postStream = request.GetRequestStream()
postStream.Write(byteArray, 0, byteArray.Length)
Finally
If Not postStream Is Nothing Then postStream.Close()
End Try
'' Get response
response = DirectCast(request.GetResponse(), HttpWebResponse)
reader = New System.IO.StreamReader(response.GetResponseStream(), Encoding.ASCII)
WebString = reader.ReadToEnd()
Finally
If Not response Is Nothing Then response.Close()
End Try
End Sub
Thanks again.