RESTful knowledge exchange
Post Reply
dannordquist
Enthusiast
Posts: 27
Liked: 2 times
Joined: Oct 23, 2014 3:39 pm
Full Name: Dan Nordquist
Contact:

how to send the header correctly with c# for authentication

Post by dannordquist »

I've tried many variations of code but this is the gist:

Code: Select all

HttpWebRequest httpWReq = (HttpWebRequest)HttpWebRequest.Create("http://mysite:9399/api/sessionMngr/");
                httpWReq.Method = "POST";

                ASCIIEncoding encode = new ASCIIEncoding();
                string _auth = string.Format("{0}:{1}", "user", "pass");
                string _enc = Convert.ToBase64String(encode.GetBytes(_auth));
                string _cred = string.Format("{0} {1}", "Basic", _enc);
                byte[] data = encode.GetBytes(_cred);
                httpWReq.ContentLength = _cred.Length;
                httpWReq.Headers[HttpRequestHeader.Authorization] = _cred;
                
                string responseString = new StreamReader(httpWReq.GetResponse().GetResponseStream()).ReadToEnd();

                Console.WriteLine(responseString);
I get a 500 error from the server.

Any ideas?

Thanks!
dannordquist
Enthusiast
Posts: 27
Liked: 2 times
Joined: Oct 23, 2014 3:39 pm
Full Name: Dan Nordquist
Contact:

why is the moderator deleting my posts?

Post by dannordquist »

I've replied to several posts with related comments and they are getting deleted.

Does Veeam not want this to be successful or just want to frustrate everyone who's looking for answers?
dannordquist
Enthusiast
Posts: 27
Liked: 2 times
Joined: Oct 23, 2014 3:39 pm
Full Name: Dan Nordquist
Contact:

Re: how to send the header correctly with c# for authenticat

Post by dannordquist »

Here's the header text being sent to the server, which is exactly the correct format specified in the documentation:

Content-Type: text/xml
Authorization: Basic dmVlYW06VjMzYU0yMDEx

Still get a 500 error though...
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: how to send the header correctly with c# for authenticat

Post by veremin »

Your post were deleted, because they were the same. Meanwhile, your original topic has been preserved. Please, don't overfill multiple topics with the same issue, and keep posting in this thread.

Thank you for your understanding.
dannordquist
Enthusiast
Posts: 27
Liked: 2 times
Joined: Oct 23, 2014 3:39 pm
Full Name: Dan Nordquist
Contact:

Re: how to send the header correctly with c# for authenticat

Post by dannordquist »

I posted on several threads because people will get notification of the post, and if they found an answer it might prompt them to post it.

Posting a new thread does not notify people who have the same question.

Thank you for making this more difficult.
poulpreben
Certified Trainer
Posts: 1024
Liked: 448 times
Joined: Jul 23, 2012 8:16 am
Full Name: Preben Berg
Contact:

Re: how to send the header correctly with c# for authenticat

Post by poulpreben »

Hi Dan,

You probably want to have a look at this thread over at StackOverflow: C# webrequest authentication

I would love to try, but I never did much C# programming, so please post your findings in this thread!

Thanks,
Preben
dannordquist
Enthusiast
Posts: 27
Liked: 2 times
Joined: Oct 23, 2014 3:39 pm
Full Name: Dan Nordquist
Contact:

Re: how to send the header correctly with c# for authenticat

Post by dannordquist »

Thanks poulpreben. I've found that there's nothing wrong with my code, however. It works just fine, but the server returns a 500 error because we don't have the Enterprise Plus license. It doesn't indicate anything about licensing or why it got the 500 error, so it was difficult to find that it was just a licensing issue (wasted two days thinking it was a code issue).

Looks like it's a bit costly for the Plus license so if we can't get budget for it I'll end up figuring out the DB structure and parsing the Database instead. Won't be able to do anything but read information but better than nothing.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: how to send the header correctly with c# for authenticat

Post by veremin »

What about using PowerShell, instead of parsing DB? Not only will be more convenient, from my perspective, but also it will not be read-only stuff, as changes are totally possible via PS. Thanks.
dannordquist
Enthusiast
Posts: 27
Liked: 2 times
Joined: Oct 23, 2014 3:39 pm
Full Name: Dan Nordquist
Contact:

Re: how to send the header correctly with c# for authenticat

Post by dannordquist »

Thank you v.Eremin. Would you mind posting some example PS code to get me started on the right path? Just login and reading data (current jobs with failure/warnings and job duration would be awesome) will get me started and then I hope to find information on adding commands and/or changes after proving the functionality.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: how to send the header correctly with c# for authenticat

Post by veremin »

The best idea would be to check both PowerShell subforum and our online Help Center.

As to the script examples, the following ones should be helpful:

Get all jobs that failed during the last run

Code: Select all

Asnp VeeamPSSnapin
Get-VBRJob | where {$_.GetLastResult() -eq "Failed"}
Select all jobs along with the start and end time of their latest sessions:

Code: Select all

Asnp VeeamPSSnapin
Get-VBRJob | select name, {$_.Findlastsession().creationTime}, {$_.Findlastsession().EndTime}
If you want to continue discussion regarding PS, please, create a separate topic on the said subforum.

Thanks.
dannordquist
Enthusiast
Posts: 27
Liked: 2 times
Joined: Oct 23, 2014 3:39 pm
Full Name: Dan Nordquist
Contact:

Re: how to send the header correctly with c# for authenticat

Post by dannordquist »

Excellent! thank you!
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: how to send the header correctly with c# for authenticat

Post by veremin »

You're welcome. Should other questions arise, feel free to contact us. Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests