com.sola.instagram.io.PostMethod Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of instagram-java Show documentation
Show all versions of instagram-java Show documentation
Java wrapper for Instagram API v1.
package com.sola.instagram.io;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.io.InputStream;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.message.BasicNameValuePair;
public class PostMethod extends APIMethod {
Map postParameters;
public PostMethod() {
super();
this.type = "POST";
}
public PostMethod(String methodUri) {
super(methodUri);
this.type = "POST";
}
@Override
protected InputStream performRequest() {
HttpResponse response;
HttpPost post = new HttpPost(this.methodUri);
List nameValuePairs = new ArrayList(1);
for (Map.Entry arg : getPostParameters().entrySet()) {
nameValuePairs.add(new BasicNameValuePair(arg.getKey(), arg.getValue().toString()));
}
InputStream stream = null;
try {
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response = client.execute(post);
stream = response.getEntity().getContent();
} catch (Exception e) {
e.printStackTrace();
}
return stream;
}
public Map getPostParameters() {
return postParameters;
}
public PostMethod setPostParameters(Map postParameters) {
this.postParameters = postParameters;
return this;
}
}