• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 67
  • Last Modified:

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 ...
1
Tech_Men
Asked:
Tech_Men
  • 4
  • 3
1 Solution
 
Ryan ChongCommented:
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 ChongCommented:
a worked sample could be vary subjected to actual requirements.

do you have documentation on how you should call the remote URL?
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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 ChongCommented:
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
 
Tech_MenAuthor Commented:
thx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now