Created
October 11, 2011 16:32
-
-
Save bobbungee/1278611 to your computer and use it in GitHub Desktop.
Mathbrain Spam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package rishi.betacos; | |
import java.io.*; | |
import java.net.*; | |
import java.util.HashMap; | |
import java.util.Iterator; | |
import java.util.Map; | |
/** | |
* | |
* @author Rishi Shah | |
*/ | |
public class BetacosConnection { | |
private URL url; | |
private OutputStream out; | |
public BetacosConnection(URL url, OutputStream out) { | |
this.url = url; | |
this.out = out; | |
} | |
public void post(Map<String, String> map) throws IOException { | |
HttpURLConnection connection = (HttpURLConnection)url.openConnection(); | |
connection.setDoOutput(true); | |
OutputStreamWriter os = new OutputStreamWriter(connection.getOutputStream()); | |
Map<String, String> data = clean(map); | |
Iterator<String> keys = data.keySet().iterator(); | |
StringBuilder query = new StringBuilder(); | |
while (keys.hasNext()) { | |
String key = keys.next(); | |
query.append(key); | |
query.append("="); | |
query.append(data.get(key)); | |
query.append("&"); | |
} | |
query.deleteCharAt(query.length()-1); | |
os.write(query.toString()); | |
os.close(); | |
BufferedReader in = new BufferedReader( | |
new InputStreamReader( | |
connection.getInputStream())); | |
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out)); | |
String decodedString = null; | |
while ((decodedString = in.readLine()) != null) { | |
bw.write(decodedString); | |
bw.flush(); | |
} | |
in.close(); | |
} | |
private Map<String, String> clean(Map<String, String> data) throws UnsupportedEncodingException { | |
Iterator<String> keys = data.keySet().iterator(); | |
Map<String, String> map = new HashMap<String, String>(); | |
while (keys.hasNext()) { | |
String key = keys.next(); | |
String value = URLEncoder.encode(data.get(key), "UTF-8"); | |
map.put(key, value); | |
} | |
return map; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package rishi.betacos; | |
import java.io.*; | |
import java.net.*; | |
import java.util.*; | |
/** | |
* | |
* @author Rishi Shah | |
*/ | |
public class RunBetacosConnection { | |
public static void main(String[] args) throws Exception { | |
URL url = new URL("http://www.mathbrain.tk/code/tahir/index.php"); | |
Map<String, String> params = new HashMap<String, String>(); | |
params.put("username", "benjew"); | |
params.put("name", "ALIAMAN CHAROLIA"); | |
params.put("url", "http://www.google.com/search?q=lol"); | |
params.put("comments", "lolololo"); | |
params.put("sum", "3"); | |
params.put("sumcheck", "3"); | |
params.put("check", "true"); | |
BetacosConnection bc = new BetacosConnection(url, System.out); | |
bc.post(params); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment