Skip to content

Instantly share code, notes, and snippets.

@dogeared
Created February 8, 2011 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dogeared/816380 to your computer and use it in GitHub Desktop.
Save dogeared/816380 to your computer and use it in GitHub Desktop.
Replacement code in NodeService
public String post(Service serviceName, Map<String, String> params) throws IOException {
StringBuffer sb = new StringBuffer();
for (String key:params.keySet()) {
String value = params.get(key);
sb.append(key+"="+value+"&");
}
String urlParameters = sb.substring(0,sb.length()-1);
URL url;
HttpURLConnection connection = null;
StringBuffer response = new StringBuffer();
url = new URL(config.getProperty(serviceName.value));
connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
connection.setRequestProperty("Content-Language", "en-US");
connection.setUseCaches (false);
connection.setDoInput(true);
connection.setDoOutput(true);
//Send request
DataOutputStream wr = new DataOutputStream (connection.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
//Get Response
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
while((line = rd.readLine()) != null) {
response.append(line);
response.append('\r');
}
rd.close();
if(connection != null) {
connection.disconnect();
}
return response.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment