How to access POST form fields in Express

Things have changed once again starting Express 4.16.0, you can now use express.json() and express.urlencoded() just like in Express 3.0. This was different starting Express 4.0 to 4.15: $ npm install –save body-parser and then: var bodyParser = require(‘body-parser’) app.use( bodyParser.json() ); // to support JSON-encoded bodies app.use(bodyParser.urlencoded({ // to support URL-encoded bodies extended: true … Read more

How to add parameters to HttpURLConnection using POST using NameValuePair

You can get output stream for the connection and write the parameter query string to it. URL url = new URL(“http://yoururl.com”); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); conn.setReadTimeout(10000); conn.setConnectTimeout(15000); conn.setRequestMethod(“POST”); conn.setDoInput(true); conn.setDoOutput(true); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair(“firstParam”, paramValue1)); params.add(new BasicNameValuePair(“secondParam”, paramValue2)); params.add(new BasicNameValuePair(“thirdParam”, paramValue3)); OutputStream os = conn.getOutputStream(); BufferedWriter writer = new BufferedWriter( new … Read more

Sending HTTP POST Request In Java

Updated Answer: Since some of the classes, in the original answer, are deprecated in the newer version of Apache HTTP Components, I’m posting this update. By the way, you can access the full documentation for more examples here. HttpClient httpclient = HttpClients.createDefault(); HttpPost httppost = new HttpPost(“http://www.a-domain.com/foo/”); // Request parameters and other properties. List<NameValuePair> params … Read more

application/x-www-form-urlencoded or multipart/form-data?

TL;DR Summary; if you have binary (non-alphanumeric) data (or a significantly sized payload) to transmit, use multipart/form-data. Otherwise, use application/x-www-form-urlencoded. The MIME types you mention are the two Content-Type headers for HTTP POST requests that user-agents (browsers) must support. The purpose of both of those types of requests is to send a list of name/value … Read more

How do I send a POST request with PHP?

CURL-less method with PHP5: $url=”http://server.com/path”; $data = array(‘key1’ => ‘value1’, ‘key2’ => ‘value2’); // use key ‘http’ even if you send the request to https://… $options = array( ‘http’ => array( ‘header’ => “Content-type: application/x-www-form-urlencoded\r\n”, ‘method’ => ‘POST’, ‘content’ => http_build_query($data) ) ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); if ($result === FALSE) … Read more

How to get POSTed JSON in Flask?

First of all, the .json attribute is a property that delegates to the request.get_json() method, which documents why you see None here. You need to set the request content type to application/json for the .json property and .get_json() method (with no arguments) to work as either will produce None otherwise. See the Flask Request documentation: … Read more