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

Tech_Men
Tech_Men used Ask the Experts™
on
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 ...
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Ryan ChongSoftware Team Lead

Commented:
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/

Author

Commented:
hi ,
maybe u have a small sample that works?
Ryan ChongSoftware Team Lead

Commented:
a worked sample could be vary subjected to actual requirements.

do you have documentation on how you should call the remote URL?
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Author

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

this in the header :
"encrypt","XXXX"

Author

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 ?
Software Team Lead
Commented:
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.

Author

Commented:
thx

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial