Leon Taljaard
asked on
Invoke-WebRequest with basic authentication
Hi Guys,
I have a web service i need to get the XML returned from but it requires basic authentication, so I am needing some help on formatting the PowerShell script.
The web service has a specific method I need to call as well as to variables that I need to pass with specific values, on variable is "Datsource" and the other is "CustomerID"
Some help on getting the basic authentication added would be a great help please, i have the script working but it fails with an error 400 Bad Request.
This is what I have so far
I have a web service i need to get the XML returned from but it requires basic authentication, so I am needing some help on formatting the PowerShell script.
The web service has a specific method I need to call as well as to variables that I need to pass with specific values, on variable is "Datsource" and the other is "CustomerID"
Some help on getting the basic authentication added would be a great help please, i have the script working but it fails with an error 400 Bad Request.
This is what I have so far
$Datasource = 'Value'
$CustomerID ='Value'
Invoke-WebRequest "http://ServerName/CustomerCareServiceV1.3.1/ProductService.svc/Basic/GetAvailableProducts?DataSource=$Datasource&CustomerID=$CustomerID&CustomerIDSpecified=True"
ASKER
Hi Nadav,
We are at it again :)
I have tried that, I still get error 400 bad request, the problem is that I need to use "Basic" authentication
We are at it again :)
I have tried that, I still get error 400 bad request, the problem is that I need to use "Basic" authentication
Try this one, worked for me: (using basic iis authentication)
$url = "http://localhost/temp/default.htm"
$user = "userName"
$pass = "pass..."
$secPass = convertTo-secureString $pass -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($user,$secPass)
$data = Invoke-RestMethod $url -Credential $cred
$data
ASKER
This is what i have just tried
The method is GetAvailableProductsw
This is the XML Payload Request required
$Datasource = 'DTH'
$CustomerID ='36526867'
$url = "http://23RNB-W4INT01/CustomerCareServiceV1.3.1/ProductService.svc/GetAvailableProducts?DataSource=$Datasource&CustomerID=$CustomerID&CustomerIDSpecified=True"
$user = "za\btgaccount"
$pass = "BTG@ccount2"
$secPass = convertTo-secureString $pass -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($user,$secPass)
$data = Invoke-RestMethod $url -Credential $cred
$data
I still get 400 bad request.The method is GetAvailableProductsw
This is the XML Payload Request required
<Datasource>String</Datasource>
<CustomerID>0</CustomerID>
<CustomerIDSpecified>True</CustomerIDSpecified>
First try without the domain (just for the test) second if you browse to that url using internet explorer do you get a prompt for user and password? if you type this user and password does it work?
By saying without the domain I mean just the username not domain\username
Getavailableproducts is a file or virtual directory?
ASKER
Hi Nadav,
Sorry for the delayed response.
You cannot open that URL normally by browsing to it. The "Getavailableproducts" is a method name which requires datasource, customerid and customeridspecified values to be passed to it.
Sorry for the delayed response.
You cannot open that URL normally by browsing to it. The "Getavailableproducts" is a method name which requires datasource, customerid and customeridspecified values to be passed to it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I managed to get this worked out by changing the method i was calling and using the full method name with the endpoint
https://technet.microsoft.com/en-us/library/hh849901.aspx