80,350
社区成员
发帖
与我相关
我的任务
分享
/**
* A HTTP request(POST) with given URL
*
* @param strUrl
* the URL you want to request
* @return
*/
public static String post(String url) throws ClientProtocolException, IOException {
String result = "";
HttpPost request = new HttpPost(url);
HttpParams httpParameters = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is established.
int timeoutConnection = 10 * 1000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
// Set the default socket timeout in milliseconds which is the timeout
// for waiting for data.
int timeoutSocket = 10 * 1000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
HttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpResponse response = httpClient.execute(request);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
result = EntityUtils.toString(response.getEntity());
}
return result;
}