use of org.qii.weiciyuan.support.utils.GlobalContext in project weiciyuan by qii.
the class JavaHttpUtility method doPost.
public String doPost(String urlAddress, Map<String, String> param) throws WeiboException {
GlobalContext globalContext = GlobalContext.getInstance();
String errorStr = globalContext.getString(R.string.timeout);
globalContext = null;
try {
URL url = new URL(urlAddress);
Proxy proxy = getProxy();
HttpsURLConnection uRLConnection;
if (proxy != null) {
uRLConnection = (HttpsURLConnection) url.openConnection(proxy);
} else {
uRLConnection = (HttpsURLConnection) url.openConnection();
}
uRLConnection.setDoInput(true);
uRLConnection.setDoOutput(true);
uRLConnection.setRequestMethod("POST");
uRLConnection.setUseCaches(false);
uRLConnection.setConnectTimeout(CONNECT_TIMEOUT);
uRLConnection.setReadTimeout(READ_TIMEOUT);
uRLConnection.setInstanceFollowRedirects(false);
uRLConnection.setRequestProperty("Connection", "Keep-Alive");
uRLConnection.setRequestProperty("Charset", "UTF-8");
uRLConnection.setRequestProperty("Accept-Encoding", "gzip, deflate");
uRLConnection.connect();
DataOutputStream out = new DataOutputStream(uRLConnection.getOutputStream());
out.write(Utility.encodeUrl(param).getBytes());
out.flush();
out.close();
return handleResponse(uRLConnection);
} catch (IOException e) {
e.printStackTrace();
throw new WeiboException(errorStr, e);
}
}
Aggregations