HTTP POST Returns Error: 417 “Expectation Failed.”

When I try to POST to a URL it results in the following exception: The remote server returned an error: (417) Expectation Failed. Here’s a sample code: var client = new WebClient(); var postData = new NameValueCollection(); postData.Add(“postParamName”, “postParamValue”); byte[] responseBytes = client.UploadValues(“http://…”, postData); string response = Encoding.UTF8.GetString(responseBytes); // (417) Expectation Failed. Using an HttpWebRequest/HttpWebResponse … Read more

How do I POST a x-www-form-urlencoded request using Fetch?

I have some parameters that I want to POST form-encoded to my server: { ‘userName’: ‘[email protected]’, ‘password’: ‘Password!’, ‘grant_type’: ‘password’ } I’m sending my request (currently without parameters) like this var obj = { method: ‘POST’, headers: { ‘Content-Type’: ‘application/x-www-form-urlencoded; charset=UTF-8’, }, }; fetch(‘https://example.com/login’, obj) .then(function(res) { // Do stuff with result }); How can … Read more

How to add parameters to HttpURLConnection using POST using NameValuePair

I am trying to do POST with HttpURLConnection(I need to use it this way, can’t use HttpPost) and I’d like to add parameters to that connection such as post.setEntity(new UrlEncodedFormEntity(nvp)); where nvp = new ArrayList<NameValuePair>(); having some data stored in. I can’t find a way how to add this ArrayList to my HttpURLConnection which is … Read more