i trying to make a POST but i am getting 400 error msg

this is the code :

 
using (var wb = new WebClient())
            {
                var data = new NameValueCollection();
                data["username"] = "adam";
                data["password"] = "1234";

                wb.Headers.Set("encrypt","XXXX");
                var response = wb.UploadValues("http://XXXXXX/api/login", "POST", data);
                return response.ToString();
             }

Open in new window


the user and password I need to send in the body of the request

the error msg :
The remote server returned an error: (400) Bad Request.
what is wrong?
thanks ...
Tech_MenAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
The remote server returned an error: (400) Bad Request.
few things to verify:

1. you may specify the request method whether it's POST, PUT, GET ,etc
2. make sure the request header is correct
3. make sure the data to be sent is correct

try use tool such as Postman to do a separate testing when necessary.
https://www.getpostman.com/
0
Tech_MenAuthor Commented:
hi ,
maybe u have a small sample that works?
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
a worked sample could be vary subjected to actual requirements.

do you have documentation on how you should call the remote URL?
0
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

Tech_MenAuthor Commented:
this data i need to set in the body :
data["username"] = "adam";
data["password"] = "1234";

this in the header :
"encrypt","XXXX"
0
Tech_MenAuthor Commented:
ok now i am getting the response no error msg
var response = wb.UploadValues("http://XXXX", "POST", data);
but the data in the response its not that the data that i need to see its just an array of numbers maybe i need to do some cast for the real data to come out ?
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
but the data in the response its not that the data that i need to see its just an array of numbers maybe i need to do some cast for the real data to come out ?
if you get a response status 200 which mean the request is good where it returns a valid response.

try to check the documentation available on what it meant by referring to these array of numbers.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tech_MenAuthor Commented:
thx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.