use of weibo4j.model.PostParameter in project twitter-2-weibo by rjyo.
the class HttpClient method get.
public Response get(String url, PostParameter[] params, Paging paging) throws WeiboException {
if (null != paging) {
List<PostParameter> pagingParams = new ArrayList<PostParameter>(4);
if (-1 != paging.getMaxId()) {
pagingParams.add(new PostParameter("max_id", String.valueOf(paging.getMaxId())));
}
if (-1 != paging.getSinceId()) {
pagingParams.add(new PostParameter("since_id", String.valueOf(paging.getSinceId())));
}
if (-1 != paging.getPage()) {
pagingParams.add(new PostParameter("page", String.valueOf(paging.getPage())));
}
if (-1 != paging.getCount()) {
if (-1 != url.indexOf("search")) {
// search api takes "rpp"
pagingParams.add(new PostParameter("rpp", String.valueOf(paging.getCount())));
} else {
pagingParams.add(new PostParameter("count", String.valueOf(paging.getCount())));
}
}
PostParameter[] newparams = null;
PostParameter[] arrayPagingParams = pagingParams.toArray(new PostParameter[pagingParams.size()]);
if (null != params) {
newparams = new PostParameter[params.length + pagingParams.size()];
System.arraycopy(params, 0, newparams, 0, params.length);
System.arraycopy(arrayPagingParams, 0, newparams, params.length, pagingParams.size());
} else {
if (0 != arrayPagingParams.length) {
String encodedParams = HttpClient.encodeParameters(arrayPagingParams);
if (-1 != url.indexOf("?")) {
url += "&" + encodedParams;
} else {
url += "?" + encodedParams;
}
}
}
return get(url, newparams);
} else {
return get(url, params);
}
}
use of weibo4j.model.PostParameter in project twitter-2-weibo by rjyo.
the class HttpClient method multPartURL.
/**
* 支持multipart方式上传图片
*
*/
public Response multPartURL(String url, PostParameter[] params, ImageItem item) throws WeiboException {
PostMethod postMethod = new PostMethod(url);
try {
Part[] parts = null;
if (params == null) {
parts = new Part[1];
} else {
parts = new Part[params.length + 1];
}
if (params != null) {
int i = 0;
for (PostParameter entry : params) {
parts[i++] = new StringPart(entry.getName(), (String) entry.getValue());
}
parts[parts.length - 1] = new ByteArrayPart(item.getContent(), item.getName(), item.getContentType());
}
postMethod.setRequestEntity(new MultipartRequestEntity(parts, postMethod.getParams()));
return httpRequest(postMethod);
} catch (Exception ex) {
throw new WeiboException(ex.getMessage(), ex, -1);
}
}
use of weibo4j.model.PostParameter in project twitter-2-weibo by rjyo.
the class HttpClient method multPartURL.
public Response multPartURL(String fileParamName, String url, PostParameter[] params, File file, boolean authenticated) throws WeiboException {
PostMethod postMethod = new PostMethod(url);
try {
Part[] parts = null;
if (params == null) {
parts = new Part[1];
} else {
parts = new Part[params.length + 1];
}
if (params != null) {
int i = 0;
for (PostParameter entry : params) {
parts[i++] = new StringPart(entry.getName(), (String) entry.getValue());
}
}
FilePart filePart = new FilePart(fileParamName, file.getName(), file, new MimetypesFileTypeMap().getContentType(file), "UTF-8");
filePart.setTransferEncoding("binary");
parts[parts.length - 1] = filePart;
postMethod.setRequestEntity(new MultipartRequestEntity(parts, postMethod.getParams()));
return httpRequest(postMethod);
} catch (Exception ex) {
throw new WeiboException(ex.getMessage(), ex, -1);
}
}
Aggregations