-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alexander James Wallar
committed
Jan 19, 2014
1 parent
899a6fb
commit 02e8172
Showing
55 changed files
with
101 additions
and
5,252 deletions.
There are no files selected for viewing
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
Binary file not shown.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.locaudio.net; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.nio.CharBuffer; | ||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
|
||
import org.apache.http.HttpEntity; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.ClientProtocolException; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.entity.UrlEncodedFormEntity; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.client.methods.HttpPost; | ||
import org.apache.http.impl.client.DefaultHttpClient; | ||
import org.apache.http.message.BasicNameValuePair; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
public class Requests { | ||
|
||
private String ipAddress = null; | ||
private int port = 80; | ||
private String url = null; | ||
private static final int CHAR_BUFFER_SIZE = 256; | ||
|
||
public Requests() { | ||
this.ipAddress = "localhost"; | ||
this.port = 8000; | ||
this.url = this.ipAddress + ":" + this.port; | ||
} | ||
|
||
public Requests(String ipAddress, int port) { | ||
this.ipAddress = ipAddress; | ||
this.port = port; | ||
this.url = this.ipAddress + ":" + this.port; | ||
} | ||
|
||
public JSONObject post(Map<String, String> paramMap) | ||
throws ClientProtocolException, IOException, JSONException { | ||
HttpClient httpclient = new DefaultHttpClient(); | ||
HttpPost httppost = new HttpPost(this.url); | ||
|
||
// Request parameters and other properties. | ||
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); | ||
|
||
Iterator<Entry<String, String>> it = paramMap.entrySet().iterator(); | ||
Entry<String, String> pair = null; | ||
|
||
while (it.hasNext()) { | ||
pair = (Entry<String, String>) it.next(); | ||
params.add(new BasicNameValuePair(pair.getKey(), pair.getValue())); | ||
} | ||
|
||
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); | ||
|
||
// Execute and get the response. | ||
HttpResponse response = httpclient.execute(httppost); | ||
HttpEntity entity = response.getEntity(); | ||
|
||
if (entity != null) { | ||
InputStreamReader reader = new InputStreamReader( | ||
entity.getContent()); | ||
try { | ||
CharBuffer target = CharBuffer.allocate(CHAR_BUFFER_SIZE); | ||
reader.read(target); | ||
return new JSONObject(target.toString()); | ||
} finally { | ||
reader.close(); | ||
} | ||
} else { | ||
return new JSONObject(); | ||
} | ||
} | ||
|
||
public JSONObject get(String... params) { | ||
return new JSONObject(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.