Send UTF-8 to Pastebin
This commit is contained in:
parent
a937308d3d
commit
940c6f44a3
@ -11,7 +11,7 @@ import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
import org.apache.http.message.BasicNameValuePair;
|
import org.apache.http.message.BasicNameValuePair;
|
||||||
import org.apache.http.params.HttpParams;
|
import org.apache.http.protocol.HTTP;
|
||||||
|
|
||||||
public class PastebinClient {
|
public class PastebinClient {
|
||||||
private static final String API_DEV_KEY = "api_dev_key";
|
private static final String API_DEV_KEY = "api_dev_key";
|
||||||
@ -28,6 +28,8 @@ public class PastebinClient {
|
|||||||
private static final String API_ERROR = "Bad API request,";
|
private static final String API_ERROR = "Bad API request,";
|
||||||
|
|
||||||
public static class APIException extends Exception {
|
public static class APIException extends Exception {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private APIException(final String message) {
|
private APIException(final String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
@ -48,14 +50,6 @@ public class PastebinClient {
|
|||||||
this.apiDevKey = apiDevKey;
|
this.apiDevKey = apiDevKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String paste(final String code) throws Exception {
|
|
||||||
return this.paste(code, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String paste(final String code, final String name) throws Exception {
|
|
||||||
return this.paste(code, name, Format.NONE, false, Expiration.DAY_1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void login(final String name, final String password)
|
public void login(final String name, final String password)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
final List<NameValuePair> params = new LinkedList<NameValuePair>();
|
final List<NameValuePair> params = new LinkedList<NameValuePair>();
|
||||||
@ -65,7 +59,7 @@ public class PastebinClient {
|
|||||||
|
|
||||||
final HttpPost request =
|
final HttpPost request =
|
||||||
new HttpPost("http://pastebin.com/api/api_login.php");
|
new HttpPost("http://pastebin.com/api/api_login.php");
|
||||||
request.setEntity(new UrlEncodedFormEntity(params));
|
request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
|
||||||
|
|
||||||
final HttpResponse response = this.httpClient.execute(request);
|
final HttpResponse response = this.httpClient.execute(request);
|
||||||
final String content =
|
final String content =
|
||||||
@ -89,7 +83,7 @@ public class PastebinClient {
|
|||||||
|
|
||||||
final HttpPost request =
|
final HttpPost request =
|
||||||
new HttpPost("http://pastebin.com/api/api_post.php");
|
new HttpPost("http://pastebin.com/api/api_post.php");
|
||||||
request.setEntity(new UrlEncodedFormEntity(params));
|
request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
|
||||||
|
|
||||||
final HttpResponse response = this.httpClient.execute(request);
|
final HttpResponse response = this.httpClient.execute(request);
|
||||||
final String content =
|
final String content =
|
||||||
@ -98,12 +92,37 @@ public class PastebinClient {
|
|||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setParameter(final HttpParams params,
|
public String paste(final String code) throws Exception {
|
||||||
final String name, final Object value) {
|
return this.paste(code, null, Format.NONE, false, Expiration.DAY_1);
|
||||||
if (value == null) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
params.setParameter(name, value);
|
|
||||||
|
public String paste(final String code, final String name) throws Exception {
|
||||||
|
return this.paste(code, name, Format.NONE, false, Expiration.DAY_1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String paste(final String code, final String name,
|
||||||
|
final Format format) throws Exception {
|
||||||
|
return this.paste(code, name, format, false, Expiration.DAY_1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String paste(final String code, final Format format)
|
||||||
|
throws Exception {
|
||||||
|
return this.paste(code, null, format, false, Expiration.DAY_1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String paste(final String code, final Expiration expiration)
|
||||||
|
throws Exception {
|
||||||
|
return this.paste(code, null, Format.NONE, false, expiration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String paste(final String code, final Format format,
|
||||||
|
final Expiration expiration) throws Exception {
|
||||||
|
return this.paste(code, null, format, false, expiration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String paste(final String code, final String name,
|
||||||
|
final Format format, final Expiration expiration) throws Exception {
|
||||||
|
return this.paste(code, name, format, false, expiration);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setParameter(final List<NameValuePair> params,
|
private static void setParameter(final List<NameValuePair> params,
|
||||||
|
Loading…
Reference in New Issue
Block a user