当前位置: 首页>>代码示例>>Java>>正文


Java DefaultHttpClient.execute方法代码示例

本文整理汇总了Java中org.apache.http.impl.client.DefaultHttpClient.execute方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultHttpClient.execute方法的具体用法?Java DefaultHttpClient.execute怎么用?Java DefaultHttpClient.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.impl.client.DefaultHttpClient的用法示例。


在下文中一共展示了DefaultHttpClient.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doInBackground

import org.apache.http.impl.client.DefaultHttpClient; //导入方法依赖的package包/类
@Override
protected List<String> doInBackground(String... url) {
    List<String> jsons = new ArrayList<String>();
    //Laço de repetição que percorre os quatro bimestres
    for(int i=0;i<4;i++) {
        //Instancia um cliente http, que fará a requisição do json
        DefaultHttpClient lHttpClient = new DefaultHttpClient();
        //Define um HttpGet, que contém a url
        HttpGet lHttpGet = new HttpGet(url[0].replace("$rm", mAluno).replace("$bim",String.valueOf(i+1)));
        try {
            //Executa e obtem a resposta da página da API
            HttpResponse lHttpResponse = lHttpClient.execute(lHttpGet);
            //Lê o resultado
            BufferedReader reader = new BufferedReader(new InputStreamReader(lHttpResponse.getEntity().getContent(), "UTF-8"));

            jsons.add(reader.readLine());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return jsons;
}
 
开发者ID:alessandrojean,项目名称:order-by-android,代码行数:24,代码来源:DownloadNotas.java

示例2: setPathRangeIndexInDatabase

import org.apache.http.impl.client.DefaultHttpClient; //导入方法依赖的package包/类
public static void setPathRangeIndexInDatabase(String dbName, JsonNode jnode) throws IOException
{
	try {			
		DefaultHttpClient client = new DefaultHttpClient();
		client.getCredentialsProvider().setCredentials(
				new AuthScope(host, 8002),
				new UsernamePasswordCredentials("admin", "admin"));
		
			HttpPut put = new HttpPut("http://"+host+":8002"+ "/manage/v2/databases/"+dbName+"/properties?format=json");
			put.addHeader("Content-type", "application/json");
			put.setEntity(new StringEntity(jnode.toString()));

			HttpResponse response = client.execute(put);
			HttpEntity respEntity = response.getEntity();
			if(respEntity != null){
				String content =  EntityUtils.toString(respEntity);
				System.out.println(content);
			}
		}catch (Exception e) {
		// writing error to Log
		e.printStackTrace();
	}
}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:24,代码来源:ConnectedRESTQA.java

示例3: testEditList

import org.apache.http.impl.client.DefaultHttpClient; //导入方法依赖的package包/类
@Test
public void testEditList() throws URISyntaxException, ClientProtocolException, IOException {
    String url = "http://127.0.0.1:8080/sjk-market-admin/admin/catalogconvertor/edit.list.d";
    URIBuilder urlb = new URIBuilder(url);

    // 参数
    urlb.setParameter("id", "1,2");
    urlb.setParameter("marketName", "eoemarket,eoemarket");
    urlb.setParameter("catalog", "1,1");
    urlb.setParameter("subCatalog", "15,8");
    urlb.setParameter("subCatalogName", "系统工具,生活娱乐1");
    urlb.setParameter("targetCatalog", "1,1");
    urlb.setParameter("targetSubCatalog", "14,9");

    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(urlb.build());
    HttpResponse response = httpClient.execute(httpPost);
    logger.debug("URL:{}\n{}\n{}", url, response.getStatusLine(), response.getEntity());
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:20,代码来源:CatalogConvertorControllerTest.java

示例4: deleteRESTUser

import org.apache.http.impl.client.DefaultHttpClient; //导入方法依赖的package包/类
public static void deleteRESTUser(String usrName){
	try{
		DefaultHttpClient client = new DefaultHttpClient();

		client.getCredentialsProvider().setCredentials(
				new AuthScope(host, 8002),
				new UsernamePasswordCredentials("admin", "admin"));

		HttpDelete delete = new HttpDelete("http://"+host+":8002/manage/v2/users/"+usrName);

		HttpResponse response = client.execute(delete);
		if(response.getStatusLine().getStatusCode()== 202){
			Thread.sleep(3500);
		}
	}catch (Exception e) {
		// writing error to Log
		e.printStackTrace();
	}

}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:21,代码来源:ConnectedRESTQA.java

示例5: testEdit

import org.apache.http.impl.client.DefaultHttpClient; //导入方法依赖的package包/类
@Test
public void testEdit() throws URISyntaxException, ClientProtocolException, IOException {
    String url = "http://127.0.0.1:8080/sjk-market-admin/admin/catalogconvertor/edit.json";
    URIBuilder urlb = new URIBuilder(url);

    // 参数
    urlb.setParameter("id", "1");
    urlb.setParameter("marketName", "eoemarket");
    urlb.setParameter("catalog", "1");
    urlb.setParameter("subCatalog", "15");
    urlb.setParameter("subCatalogName", "系统工具1");
    urlb.setParameter("targetCatalog", "1");
    urlb.setParameter("targetSubCatalog", "14");

    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(urlb.build());
    HttpResponse response = httpClient.execute(httpPost);
    logger.debug("URL:{}\n{}\n{}", url, response.getStatusLine(), response.getEntity());
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:20,代码来源:CatalogConvertorControllerTest.java

示例6: setAuthentication

import org.apache.http.impl.client.DefaultHttpClient; //导入方法依赖的package包/类
public static void setAuthentication(String level,String restServerName) throws ClientProtocolException, IOException
{
	DefaultHttpClient client = new DefaultHttpClient();

	client.getCredentialsProvider().setCredentials(
			new AuthScope(host, 8002),
			new UsernamePasswordCredentials("admin", "admin"));
	String  body = "{\"authentication\": \""+level+"\"}";

	HttpPut put = new HttpPut("http://"+host+":8002/manage/v2/servers/"+restServerName+"/properties?server-type=http&group-id=Default");
	put.addHeader("Content-type", "application/json");
	put.setEntity(new StringEntity(body));

	HttpResponse response2 = client.execute(put);
	HttpEntity respEntity = response2.getEntity();
	if(respEntity != null){
		String content =  EntityUtils.toString(respEntity);
		System.out.println(content);
	}
}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:21,代码来源:ConnectedRESTQA.java

示例7: testbrokenLink

import org.apache.http.impl.client.DefaultHttpClient; //导入方法依赖的package包/类
@Test
public void testbrokenLink() throws IOException, URISyntaxException {

    JSONObject object = new JSONObject();
    object.put("key", "sprSCKKWf8xUeXxEo6Bv0lE1sSjWRDkO");
    object.put("marketName", "eoemarket");
    object.put("count", 1);
    JSONArray data = new JSONArray();
    JSONObject o = new JSONObject();
    o.put("id", -1);
    o.put("link", "http://testsssssss");
    o.put("statusCode", 404);
    data.add(o);
    object.put("data", data);

    String test = "eyJjb3VudCI6IDEwLCAibWFya2V0TmFtZSI6ICJBcHBDaGluYSIsICJkYXRhIjogW3sibGluayI6ICJodHRwOi8vd3d3LmFwcGNoaW5hLmNvbS9hcHAvY29tLmdvb2dsZS5hbmRyb2lkLmFwcHMubWFwcyIsICJpZCI6IDEsICJzdGF0dXNDb2RlIjogNDA0fSwgeyJsaW5rIjogImh0dHA6Ly93d3cuYXBwY2hpbmEuY29tL2FwcC9jb20ud2VhdGhlci5XZWF0aGVyIiwgImlkIjogMiwgInN0YXR1c0NvZGUiOiA0MDR9LCB7ImxpbmsiOiAiaHR0cDovL3d3dy5hcHBjaGluYS5jb20vYXBwL2NvbS5zdHlsZW0ud2FsbHBhcGVycyIsICJpZCI6IDQsICJzdGF0dXNDb2RlIjogNDA0fSwgeyJsaW5rIjogImh0dHA6Ly93d3cuYXBwY2hpbmEuY29tL2FwcC9jb20uc2hhemFtLmVuY29yZS5hbmRyb2lkIiwgImlkIjogNSwgInN0YXR1c0NvZGUiOiA0MDR9LCB7ImxpbmsiOiAiaHR0cDovL3d3dy5hcHBjaGluYS5jb20vYXBwL2NvbS5yaW5nZHJvaWQiLCAiaWQiOiA2LCAic3RhdHVzQ29kZSI6IDQwNH0sIHsibGluayI6ICJodHRwOi8vd3d3LmFwcGNoaW5hLmNvbS9hcHAvY29tLnAxLmNob21wc21zIiwgImlkIjogNywgInN0YXR1c0NvZGUiOiA0MDR9LCB7ImxpbmsiOiAiaHR0cDovL3d3dy5hcHBjaGluYS5jb20vYXBwL2NvbS5oYW5kY2VudC5uZXh0c21zIiwgImlkIjogOCwgInN0YXR1c0NvZGUiOiA0MDR9LCB7ImxpbmsiOiAiaHR0cDovL3d3dy5hcHBjaGluYS5jb20vYXBwL2NvbS5mYWNlYm9vay5rYXRhbmEiLCAiaWQiOiA5LCAic3RhdHVzQ29kZSI6IDQwNH0sIHsibGluayI6ICJodHRwOi8vd3d3LmFwcGNoaW5hLmNvbS9hcHAvY29tLmNvZGUuaS5tdXNpYyIsICJpZCI6IDEwLCAic3RhdHVzQ29kZSI6IDQwNH0sIHsibGluayI6ICJodHRwOi8vd3d3LmFwcGNoaW5hLmNvbS9hcHAvY29tLmJpZ2d1LnNob3BzYXZ2eSIsICJpZCI6IDExLCAic3RhdHVzQ29kZSI6IDQwNH1dLCAia2V5IjogImpqRzhMa0MzTUh5RjlYY3NWS2g2Rkh4bXRMQ05ZdE14In0=";
    Reader input = new StringReader(object.toJSONString());
    byte[] binaryData = IOUtils.toByteArray(input, "UTF-8");
    String encodeBase64 = Base64.encodeBase64String(binaryData);
    System.out.println(encodeBase64);

    String url = "http://localhost:9080/sjk-market-admin/market/brokenLink.d";
    url = "http://app.sjk.ijinshan.com/market/brokenLink.d";
    URIBuilder builder = new URIBuilder(url);
    builder.setParameter("c", test);
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(builder.build());
    HttpResponse response = httpclient.execute(httpPost);
    logger.debug("URI: {} , {}", url, response.getStatusLine());

    HttpEntity entity = response.getEntity();
    InputStream is = entity.getContent();
    // be convinient to debug
    String rspJSON = IOUtils.toString(is, "UTF-8");
    System.out.println(rspJSON);
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:37,代码来源:ControllerTest.java

示例8: callWebProxy

import org.apache.http.impl.client.DefaultHttpClient; //导入方法依赖的package包/类
public void callWebProxy(String url) {
    String resultCode = "";
    DefaultHttpClient httpclient = new DefaultHttpClient();
    try {
        HttpGet httpget = new HttpGet(url);
        HttpResponse response = httpclient.execute(httpget);

        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == HttpStatus.SC_OK) {
            HttpEntity entity = response.getEntity();
            resultCode = ResponseCode.CALLRESPONSEERROR;
            if (entity != null) {
                String responseString = EntityUtils.toString(entity);
                if (responseString.contains("Spark Jobs") && responseString.contains("Stages")
                        && responseString.contains("Storage") && responseString.contains("Environment")
                        && responseString.contains("Executors")) {
                    resultCode = ResponseCode.CALLSUCCESS;
                }
            }
        } else if (statusCode == HttpStatus.SC_MOVED_TEMPORARILY
                || statusCode == HttpStatus.SC_MOVED_PERMANENTLY) {
            resultCode = ResponseCode.CALLFORBIDDEN;
        } else {
            resultCode = ResponseCode.OTHER_RESPONSE + String.valueOf(statusCode);
        }
    } catch (Exception e) {
        LOG.warn("WebProxyCall exception " + e.getMessage());
        resultCode = ResponseCode.CALLEXCEPTION;
    } finally {
        httpclient.close();
    }
    LOG.info("WebProxyCall result " + resultCode);
    if (!resultCode.equals(ResponseCode.CALLSUCCESS)) {
        System.exit(1);
    }
}
 
开发者ID:aliyun,项目名称:aliyun-cupid-sdk,代码行数:37,代码来源:WebProxyCall.java

示例9: deleteForest

import org.apache.http.impl.client.DefaultHttpClient; //导入方法依赖的package包/类
public static void deleteForest(String fName){
	try{
		DefaultHttpClient client = new DefaultHttpClient();
		client.getCredentialsProvider().setCredentials(
				new AuthScope(host, 8002),
				new UsernamePasswordCredentials("admin", "admin"));

		HttpDelete delete = new HttpDelete("http://"+host+":8002/manage/v2/forests/"+fName+"?level=full");
		client.execute(delete);

	}catch (Exception e) {
		// writing error to Log
		e.printStackTrace();
	}
}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:16,代码来源:ConnectedRESTQA.java

示例10: createRESTServerWithDB

import org.apache.http.impl.client.DefaultHttpClient; //导入方法依赖的package包/类
public static void createRESTServerWithDB(String restServerName,int restPort)	{
	try{
		DefaultHttpClient client = new DefaultHttpClient();

		client.getCredentialsProvider().setCredentials(
				new AuthScope(host, 8002),
				new UsernamePasswordCredentials("admin", "admin"));
		HttpPost post = new HttpPost("http://"+host+":8002"+ "/v1/rest-apis?format=json");
		//			
		String JSONString = 
				"{ \"rest-api\": {\"name\":\""+
						restServerName +
						"\",\"port\":\""+
						restPort+
						"\"}}";
		//System.out.println(JSONString);		
		post.addHeader("Content-type", "application/json");
		post.setEntity(new StringEntity(JSONString));

		HttpResponse response = client.execute(post);
		HttpEntity respEntity = response.getEntity();

		if (respEntity != null) {
			// EntityUtils to get the response content
			String content =  EntityUtils.toString(respEntity);
			System.out.println(content);
		}
	}catch (Exception e) {
		// writing error to Log
		e.printStackTrace();
	}
}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:33,代码来源:ConnectedRESTQA.java

示例11: detachForest

import org.apache.http.impl.client.DefaultHttpClient; //导入方法依赖的package包/类
public static void detachForest(String dbName, String fName){
	try{
		DefaultHttpClient client = new DefaultHttpClient();

		client.getCredentialsProvider().setCredentials(
				new AuthScope(host, 8002),
				new UsernamePasswordCredentials("admin", "admin"));

		HttpPost post = new HttpPost("http://"+host+":8002"+ "/manage/v2/forests/"+fName);
		//			
		List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
		urlParameters.add(new BasicNameValuePair("state", "detach"));
		urlParameters.add(new BasicNameValuePair("database", dbName));

		post.setEntity(new UrlEncodedFormEntity(urlParameters));

		HttpResponse response = client.execute(post);
		HttpEntity respEntity = response.getEntity();

		if (respEntity != null) {
			// EntityUtils to get the response content
			String content =  EntityUtils.toString(respEntity);
			System.out.println(content);
		}
	}catch (Exception e) {
		// writing error to Log
		e.printStackTrace();
	}	
}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:30,代码来源:ConnectedRESTQA.java

示例12: deleteElementRangeIndexTemporalCollection

import org.apache.http.impl.client.DefaultHttpClient; //导入方法依赖的package包/类
public static void deleteElementRangeIndexTemporalCollection(String dbName, String collectionName) throws Exception
{
	DefaultHttpClient client = new DefaultHttpClient();
	client.getCredentialsProvider().setCredentials(
			new AuthScope(host, 8002),
			new UsernamePasswordCredentials("admin", "admin"));

	HttpDelete del = new HttpDelete("http://"+host+":8002/manage/v2/databases/"+ dbName + "/temporal/collections?collection=" + collectionName + "&format=json");

	del.addHeader("Content-type", "application/json");
	del.addHeader("accept", "application/json");

	HttpResponse response = client.execute(del);
	HttpEntity respEntity = response.getEntity();
	if( response.getStatusLine().getStatusCode() == 400)
	{
		HttpEntity entity = response.getEntity();
		String responseString = EntityUtils.toString(entity, "UTF-8");
		System.out.println(responseString);
	}
	else if (respEntity != null) {
		// EntityUtils to get the response content
		String content =  EntityUtils.toString(respEntity);
		System.out.println(content);
	}
	else {
		System.out.println("Collection: " + collectionName + " deleted");
		System.out.println("==============================================================");
	}
}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:31,代码来源:ConnectedRESTQA.java

示例13: deleteElementRangeIndexTemporalAxis

import org.apache.http.impl.client.DefaultHttpClient; //导入方法依赖的package包/类
public static void deleteElementRangeIndexTemporalAxis(String dbName, String axisName) throws Exception
{
	DefaultHttpClient client = new DefaultHttpClient();
	client.getCredentialsProvider().setCredentials(
			new AuthScope(host, 8002),
			new UsernamePasswordCredentials("admin", "admin"));

	HttpDelete del = new HttpDelete("http://"+host+":8002/manage/v2/databases/"+ dbName + "/temporal/axes/" + axisName + "?format=json");

	del.addHeader("Content-type", "application/json");
	del.addHeader("accept", "application/json");

	HttpResponse response = client.execute(del);
	HttpEntity respEntity = response.getEntity();
	if( response.getStatusLine().getStatusCode() == 400)
	{
		HttpEntity entity = response.getEntity();
		String responseString = EntityUtils.toString(entity, "UTF-8");
		System.out.println(responseString);
	}
	else if (respEntity != null) {
		// EntityUtils to get the response content
		String content =  EntityUtils.toString(respEntity);
		System.out.println(content);
	}
	else {
		System.out.println("Axis: " + axisName + " deleted");
		System.out.println("==============================================================");
	}
}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:31,代码来源:ConnectedRESTQA.java

示例14: HttpPost

import org.apache.http.impl.client.DefaultHttpClient; //导入方法依赖的package包/类
public static Object HttpPost(String aUrl, String aPostData) {
    String res = "";
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpPost httpost = new HttpPost(aUrl);
    try {
        httpost.setEntity(new StringEntity(aPostData, "UTF-8"));
        HttpResponse response = httpClient.execute(httpost);
        res = EntityUtils.toString(response.getEntity(), "UTF-8");
    } catch (Exception e) {
        e.printStackTrace();
    }
    return res;
}
 
开发者ID:dbiir,项目名称:rainbow,代码行数:14,代码来源:HttpUtil.java

示例15: testEdit

import org.apache.http.impl.client.DefaultHttpClient; //导入方法依赖的package包/类
@Test
public void testEdit() throws URISyntaxException, ClientProtocolException, IOException {
    String url = "http://127.0.0.1:8080/sjk-market-admin/admin/ijinshan/shift-to-ijinshan.json";
    URIBuilder urlb = new URIBuilder(url);
    // 318840 378460 hiapk 雨夜壁纸桌面主题
    // 318839 378435 hiapk APO极限滑板

    urlb.setParameter("ids", "318840,318839");
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(urlb.build());
    HttpResponse response = httpClient.execute(httpPost);
    logger.debug("URL:{}\n{}\n{}", url, response.getStatusLine(), response.getEntity());
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:14,代码来源:MarketAppControllerTest.java


注:本文中的org.apache.http.impl.client.DefaultHttpClient.execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。