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

How to process POST data in Node.js?

You can use the querystring module: var qs = require(‘querystring’); function (request, response) { if (request.method == ‘POST’) { var body = ”; request.on(‘data’, function (data) { body += data; // Too much POST data, kill the connection! // 1e6 === 1 * Math.pow(10, 6) === 1 * 1000000 ~~~ 1MB if (body.length > 1e6) … Read more

PHP, cURL, and HTTP POST example?

<?php // // A very simple PHP example that sends a HTTP POST to a remote site // $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,”http://www.example.com/tester.phtml”); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, “postvar1=value1&postvar2=value2&postvar3=value3”); // In real life you should use something like: // curl_setopt($ch, CURLOPT_POSTFIELDS, // http_build_query(array(‘postvar1’ => ‘value1’))); // Receive server response … curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $server_output = … Read more