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


Java HttpPost.releaseConnection方法代码示例

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


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

示例1: execute

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
@Override
public T execute() throws ClientProtocolException, IOException {
    HttpPost post = new HttpPost(InstagramConstants.API_URL + getUrl());
    post.addHeader("Connection", "close");
    post.addHeader("Accept", "*/*");
    post.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    post.addHeader("Cookie2", "$Version=1");
    post.addHeader("Accept-Language", "en-US");
    post.addHeader("User-Agent", InstagramConstants.USER_AGENT);
    
    log.debug("User-Agent: " + InstagramConstants.USER_AGENT);
    String payload = getPayload();
    log.debug("Base Payload: " + payload);
    
    if (isSigned()) {
        payload = InstagramHashUtil.generateSignature(payload);
    }
    log.debug("Final Payload: " + payload);
    post.setEntity(new StringEntity(payload));
    
    HttpResponse response = api.getClient().execute(post);
    api.setLastResponse(response);
    
    int resultCode = response.getStatusLine().getStatusCode();
    String content = EntityUtils.toString(response.getEntity());
    
    post.releaseConnection();

    return parseResult(resultCode, content);
}
 
开发者ID:brunocvcunha,项目名称:instagram4j,代码行数:31,代码来源:InstagramPostRequest.java

示例2: execute

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
@Override
public T execute() throws ClientProtocolException, IOException {
    HttpPost post = new HttpPost(InstagramConstants.apiUrl + getUrl());
    post.addHeader("Connection", "close");
    post.addHeader("Accept", "*/*");
    post.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    post.addHeader("Cookie2", "$Version=1");
    post.addHeader("Accept-Language", "en-US");
    post.addHeader("User-Agent", InstagramConstants.userAgent);

    String parsedData = InstagramHashing.generateSignature(getPayload());
    post.setEntity(new StringEntity(parsedData));

    HttpResponse response = InstagramContextHolder.getContext().getHttpClient().execute(post);

    int resultCode = response.getStatusLine().getStatusCode();
    String content = EntityUtils.toString(response.getEntity());

    post.releaseConnection();

    return parseResult(resultCode, content);
}
 
开发者ID:Cinderpup,项目名称:RoboInsta,代码行数:23,代码来源:InstagramPostRequest.java

示例3: refreshOauth2Token

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
/**
 * Refreshes the OAuth2 token with a refresh token.
 *
 * @param refreshToken the refresh token
 * @return Token map containing an OAuth2 access token and other info
 */
public String refreshOauth2Token( String refreshToken )
{
	final HttpPost request = new HttpPost( this.yambasHost + "/yambas/oauth/token" );
	final List<NameValuePair> data = new ArrayList<NameValuePair>( );
	data.add( new BasicNameValuePair( "grant_type", "refresh_token" ) );
	data.add( new BasicNameValuePair( "client_id", this.getAppName( ) ) );
	data.add( new BasicNameValuePair( "client_secret", this.getApiKey( ) ) );
	data.add( new BasicNameValuePair( "refresh_token", refreshToken ) );
	try
	{
		request.setEntity( new UrlEncodedFormEntity( data ) );
		final HttpResponse response = this.client.execute( request );
		final String ret = EntityUtils.toString( response.getEntity( ) );
		request.releaseConnection( );
		return ret;
	}
	catch ( final IOException e )
	{
		e.printStackTrace( );
	}
	return null;
}
 
开发者ID:ApinautenGmbH,项目名称:integration-test-helper,代码行数:29,代码来源:AomHttpClient.java

示例4: execute

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
@Override
public WxMpMaterialVideoInfoResult execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String materialId) throws WxErrorException, IOException {
  HttpPost httpPost = new HttpPost(uri);
  if (httpProxy != null) {
    RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
    httpPost.setConfig(config);
  }

  Map<String, String> params = new HashMap<>();
  params.put("media_id", materialId);
  httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params)));
  try(CloseableHttpResponse response = httpclient.execute(httpPost)){
    String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
    WxError error = WxError.fromJson(responseContent);
    if (error.getErrorCode() != 0) {
      throw new WxErrorException(error);
    } else {
      return WxMpMaterialVideoInfoResult.fromJson(responseContent);
    }
  }finally {
    httpPost.releaseConnection();
  }
}
 
开发者ID:11590692,项目名称:Wechat-Group,代码行数:24,代码来源:MaterialVideoInfoRequestExecutor.java

示例5: sendPOSTUnchecked

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
protected HttpResponse sendPOSTUnchecked(UriTemplate schema, Map<String, String> params) {
    HttpResponse httpResponse;
    try {
        HttpPost req = new HttpPost(schema.buildUri(environment.baseURI, params));
        httpResponse = this.httpClient.execute(req);
        // Buffer the response entity in memory so we can release the connection safely
        HttpEntity old = httpResponse.getEntity();
        EntityUtils.updateEntity(httpResponse, new StringEntity(EntityUtils.toString(old)));
        req.releaseConnection();
    } catch (IOException e) {
        throw new WebmateApiClientException("Error sending POST to webmate API", e);
    }
    return httpResponse;
}
 
开发者ID:webmate-io,项目名称:webmate-sdk-java,代码行数:15,代码来源:WebmateApiClient.java

示例6: getOauth2Token

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
/**
 * Fetches an OAuth2 token for the configured credentials from yambas
 *
 * @return Token map containing an OAuth2 access token and other info
 */
public String getOauth2Token( )
{
	final HttpPost request = new HttpPost( this.yambasHost + "/yambas/oauth/token" );
	final List<NameValuePair> data = new ArrayList<NameValuePair>( );
	data.add( new BasicNameValuePair( "grant_type", "aom_user" ) );
	data.add( new BasicNameValuePair( "client_id", this.getAppName( ) ) );
	data.add( new BasicNameValuePair( "client_secret", this.getApiKey( ) ) );
	data.add( new BasicNameValuePair( "scope", "read write" ) );
	data.add( new BasicNameValuePair( "username", this.getUserName( ) ) );
	data.add( new BasicNameValuePair( "app", this.getAppName( ) ) );
	data.add( new BasicNameValuePair( "password", this.getPassword( ) ) );
	data.add( new BasicNameValuePair( "system", this.getSystem( ).toString( ) ) );

	try
	{
		request.setEntity( new UrlEncodedFormEntity( data ) );
		final HttpResponse response = this.client.execute( request );
		request.releaseConnection( );
		return AomHelper.getStringFromStream( response.getEntity( ).getContent( ) );
	}
	catch ( final IOException e )
	{
		e.printStackTrace( );
	}
	return null;
}
 
开发者ID:ApinautenGmbH,项目名称:integration-test-helper,代码行数:32,代码来源:AomHttpClient.java

示例7: getResponse

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
@Override
public HttpCallObj getResponse(String apiUrl, String method) throws IOException {
	HttpCallObj result = new HttpCallObj();
	if (method != null && "POST".equals(method.toUpperCase())) {
		HttpPost httpPost = getHttpPost();
		result = responseBytes(getPostResponse(apiUrl, httpPost));
		httpPost.releaseConnection();
	} else {
		HttpGet httpGet = getHttpGet();
		result = responseBytes(getGetResponse(apiUrl, httpGet));
		httpGet.releaseConnection();
	}
	return result;
}
 
开发者ID:fier-liu,项目名称:FCat,代码行数:15,代码来源:HttpCallImpl.java

示例8: sendViaSendcloudApi

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
public void sendViaSendcloudApi(EmailParams emailParams) throws IOException {
    String url = jHipsterProperties.getSendcloud().getUrl();
    String key = jHipsterProperties.getSendcloud().getKey();
    String user = jHipsterProperties.getSendcloud().getUser();
    String from = jHipsterProperties.getSendcloud().getFrom();
    String fromName = jHipsterProperties.getSendcloud().getFromName();

    List<NameValuePair> params = new ArrayList<>();
    params.add(new BasicNameValuePair("api_user", user));
    params.add(new BasicNameValuePair("api_key", key));
    params.add(new BasicNameValuePair("to", emailParams.getTo()));
    params.add(new BasicNameValuePair("from", from));
    params.add(new BasicNameValuePair("fromname", fromName));
    params.add(new BasicNameValuePair("subject", emailParams.getSubject()));
    params.add(new BasicNameValuePair("html", emailParams.getContent()));
    params.add(new BasicNameValuePair("resp_email_id", "true"));

    HttpPost httpost = new HttpPost(url);
    HttpClient httpclient = new DefaultHttpClient();

    httpost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

    HttpResponse response = httpclient.execute(httpost);

    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        log.debug("Send email via Sendcloud successfully. response: " + EntityUtils.toString(response.getEntity()));
    } else {
        log.error("Send email via Sendcloud failed.");
    }

    httpost.releaseConnection();
}
 
开发者ID:ugouku,项目名称:shoucang,代码行数:33,代码来源:MailService.java

示例9: uploadFileToWeedFS

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
@Override
public String uploadFileToWeedFS(String url, InputStream input) throws IllegalStateException {
	HttpResponse response = null;
	HttpPost httpPost = new HttpPost(url);
	try {
		MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
		// multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
		multipartEntity.addBinaryBody("fileName", input);
		HttpEntity entity = multipartEntity.build();
		httpPost.setEntity(entity);

		response = httpClient.execute(httpPost);
		String statusCode = String.valueOf(response.getStatusLine().getStatusCode());
		if (statusCode.indexOf("20") == 0) {
			entity = response.getEntity();
			return StrUtil.readStream(entity.getContent(), responseContextEncode);
		} else if (statusCode.indexOf("40") == 0) {
			LOG.error("Page: " + url + " no find");
			return "Page no find";
		} else {
			LOG.error("返回状态码:[" + statusCode + "]");
			return "返回状态码:[" + statusCode + "]";
		}
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		httpPost.releaseConnection();
	}
	return null;
}
 
开发者ID:fier-liu,项目名称:FCat,代码行数:31,代码来源:HttpCallSSL.java

示例10: httpCall

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
@Override
public String httpCall(String apiUrl, String method, Map<String, String> parameMap) {
	String result = "";
	if (parameMap != null) {
		StringBuilder urlParame = new StringBuilder();
		Iterator<String> parameKey = parameMap.keySet().iterator();
		while (parameKey.hasNext()) {
			String parameName = parameKey.next();
			String parameVal = parameMap.get(parameName);
			if (!StrUtil.isBlank(parameVal)) {
				urlParame.append(parameName);
				urlParame.append("=");
				urlParame.append(parameVal);
				urlParame.append("&");
			}
		}
		if (urlParame.length() > 0) {
			if (urlParame.lastIndexOf("&") == urlParame.length() - 1) {
				urlParame.deleteCharAt(urlParame.length() - 1);
			}
			if (apiUrl.indexOf("?") != -1) {
				apiUrl += "&" + urlParame.toString();
			} else {
				apiUrl += "?" + urlParame.toString();
			}
		}
	}
	if (method != null && "POST".equals(method.toUpperCase())) {
		HttpPost httpPost = getHttpPost();
		result = httpPostCall(apiUrl, httpPost);
		httpPost.releaseConnection();
	} else {
		HttpGet httpGet = getHttpGet();
		result = httpGetCall(apiUrl, httpGet);
		httpGet.releaseConnection();
	}
	return result;
}
 
开发者ID:fier-liu,项目名称:FCat,代码行数:39,代码来源:HttpCallSSL.java

示例11: getResponse

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
@Override
public HttpCallObj getResponse(String apiUrl, String method, Map<String, String> parameMap) throws IOException {
	HttpCallObj result = new HttpCallObj();
	if (parameMap != null) {
		StringBuilder urlParame = new StringBuilder();
		Iterator<String> parameKey = parameMap.keySet().iterator();
		while (parameKey.hasNext()) {
			String parameName = parameKey.next();
			String parameVal = parameMap.get(parameName);
			if (!StrUtil.isBlank(parameVal)) {
				urlParame.append(parameName);
				urlParame.append("=");
				urlParame.append(parameVal);
				urlParame.append("&");
			}
		}
		if (urlParame.length() > 0) {
			if (urlParame.lastIndexOf("&") == urlParame.length() - 1) {
				urlParame.deleteCharAt(urlParame.length() - 1);
			}
			if (apiUrl.indexOf("?") != -1) {
				apiUrl += "&" + urlParame.toString();
			} else {
				apiUrl += "?" + urlParame.toString();
			}
		}
	}
	if (method != null && "POST".equals(method.toUpperCase())) {
		HttpPost httpPost = getHttpPost();
		result = responseBytes(getPostResponse(apiUrl, httpPost));
		httpPost.releaseConnection();
	} else {
		HttpGet httpGet = getHttpGet();
		result = responseBytes(getGetResponse(apiUrl, httpGet));
		httpGet.releaseConnection();
	}
	return result;
}
 
开发者ID:fier-liu,项目名称:FCat,代码行数:39,代码来源:HttpCallSSL.java

示例12: uploadFile

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
@Override
public String uploadFile(String systemName, String entityName, String apiUrl, List<File> fileList, String requestParamInputName) throws IllegalStateException {
	HttpResponse response = null;
	HttpPost httpPost = getHttpPost();
	try {
		List<BasicNameValuePair> nvps = new ArrayList<BasicNameValuePair>();
		String[] urlAndParame = apiUrl.split("\\?");
		String apiUrlNoParame = urlAndParame[0];
		Map<String, String> parameMap = StrUtil.splitUrlToParameMap(apiUrl);
		Iterator<String> parameIterator = parameMap.keySet().iterator();

		httpPost.setURI(new URI(apiUrlNoParame));
		MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
		multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
		while (parameIterator.hasNext()) {
			String parameName = parameIterator.next();
			nvps.add(new BasicNameValuePair(parameName, parameMap.get(parameName)));
			multipartEntity.addPart(parameName, new StringBody(parameMap.get(parameName), ContentType.create("text/plain", Consts.UTF_8)));
		}

		if (!StrUtil.isBlank(systemName)) {
			multipartEntity.addPart("systemName", new StringBody(systemName, ContentType.create("text/plain", Consts.UTF_8)));
		}
		if (!StrUtil.isBlank(entityName)) {
			multipartEntity.addPart("entityName", new StringBody(entityName, ContentType.create("text/plain", Consts.UTF_8)));
		}
		// 多文件上传 获取文件数组前台标签name值
		if (!StrUtil.isBlank(requestParamInputName)) {
			multipartEntity.addPart("filesName", new StringBody(requestParamInputName, ContentType.create("text/plain", Consts.UTF_8)));
		}

		if (fileList != null) {
			for (int i = 0, size = fileList.size(); i < size; i++) {
				File file = fileList.get(i);
				multipartEntity.addBinaryBody(requestParamInputName, file, ContentType.DEFAULT_BINARY, file.getName());
			}
		}
		HttpEntity entity = multipartEntity.build();
		httpPost.setEntity(entity);

		response = httpClient.execute(httpPost);
		String statusCode = String.valueOf(response.getStatusLine().getStatusCode());
		if (statusCode.indexOf("20") == 0) {
			entity = response.getEntity();
			// String contentType = entity.getContentType().getValue();//
			// application/json;charset=ISO-8859-1
			return StrUtil.readStream(entity.getContent(), responseContextEncode);
		}  else {
			LOG.error("返回状态码:[" + statusCode + "]");
			return "返回状态码:[" + statusCode + "]";
		}
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		httpPost.releaseConnection();
	}
	return null;
}
 
开发者ID:fier-liu,项目名称:FCat,代码行数:59,代码来源:HttpCallSSL.java

示例13: execute

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
@Override
public JiphyUploadResult execute() throws ClientProtocolException, IOException {

    HttpPost post = createHttpRequest();
    post.setEntity(createMultipartEntity());

    try (CloseableHttpResponse response = api.getClient().execute(post)) {
        api.setLastResponse(response);

        int resultCode = response.getStatusLine().getStatusCode();
        String content = EntityUtils.toString(response.getEntity());

        log.info("GIF Upload result: " + resultCode + ", " + content);

        post.releaseConnection();

        return parseResult(resultCode, content);
    }
}
 
开发者ID:brunocvcunha,项目名称:jiphy,代码行数:20,代码来源:JiphyUploadRequest.java

示例14: execute

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
@Override
public InstagramConfigurePhotoResult execute() throws ClientProtocolException, IOException {
    
    if (uploadId == null) {
        uploadId = String.valueOf(System.currentTimeMillis());
    }
    
    HttpPost post = createHttpRequest();
    post.setEntity(createMultipartEntity());
    
    try (CloseableHttpResponse response = api.getClient().execute(post)) {
        api.setLastResponse(response);
        
        int resultCode = response.getStatusLine().getStatusCode();
        String content = EntityUtils.toString(response.getEntity());
        
        log.info("Photo Upload result: " + resultCode + ", " + content);
        
        post.releaseConnection();

        StatusResult result = parseResult(resultCode, content);
        
        if (!result.getStatus().equalsIgnoreCase("ok")) {
            throw new RuntimeException("Error happened in photo upload: " + result.getMessage());
        }
        
        
        InstagramConfigurePhotoResult configurePhotoResult = api.sendRequest(new InstagramConfigurePhotoRequest(imageFile, uploadId, caption));
        
        log.info("Configure photo result: " + configurePhotoResult);
        if (!configurePhotoResult.getStatus().equalsIgnoreCase("ok")) {
            throw new IllegalArgumentException("Failed to configure image: " + configurePhotoResult.getMessage());
        }
        
        StatusResult exposeResult = api.sendRequest(new InstagramExposeRequest());
        log.info("Expose result: " + exposeResult);
        if (!exposeResult.getStatus().equalsIgnoreCase("ok")) {
            throw new IllegalArgumentException("Failed to expose image: " + exposeResult.getMessage());
        }

        return configurePhotoResult;
    }
}
 
开发者ID:brunocvcunha,项目名称:instagram4j,代码行数:44,代码来源:InstagramUploadPhotoRequest.java

示例15: execute

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
@Override
public StatusResult execute() throws ClientProtocolException, IOException {
    
    String url = getUrl();
    log.info("URL Upload: " + url);
    
    HttpPost post = new HttpPost(url);
    post.addHeader("X-IG-Capabilities", "3Q4=");
    post.addHeader("X-IG-Connection-Type", "WIFI");
    post.addHeader("Cookie2", "$Version=1");
    post.addHeader("Accept-Language", "en-US");
    post.addHeader("Accept-Encoding", "gzip, deflate");
    post.addHeader("Content-Type", "application/octet-stream");
    post.addHeader("Session-ID", uploadId);
    post.addHeader("Connection", "keep-alive");
    post.addHeader("Content-Disposition", "attachment; filename=\"video.mp4\"");
    post.addHeader("job", uploadJob);
    post.addHeader("Host", "upload.instagram.com");
    post.addHeader("User-Agent", InstagramConstants.USER_AGENT);
    
    log.info("User-Agent: " + InstagramConstants.USER_AGENT);

    try (FileInputStream is = new FileInputStream(videoFile)) {
        byte[] videoData = MyStreamUtils.readContentBytes(is);
        
        //TODO: long ranges? need to handle?
        int requestSize = (int) Math.floor(videoData.length / 4.0);
        int lastRequestExtra = (int) (videoData.length - (requestSize * 3));
        
        
        for (int i = 0; i < 4; i++) {
            
            int start = i * requestSize;
            int end;
            if (i == 3) {
                end = i * requestSize + lastRequestExtra;
            } else {
                end = (i + 1) * requestSize;
            }
            
            int actualLength = (i == 3 ? lastRequestExtra : requestSize);
            
            String contentRange = String.format("bytes %s-%s/%s", start, end - 1, videoData.length);
            //post.setHeader("Content-Length", String.valueOf(end - start));
            post.setHeader("Content-Range", contentRange);
            
            byte[] range = Arrays.copyOfRange(videoData, start, start + actualLength);
            log.info("Total is " + videoData.length + ", sending " + actualLength + " (starting from " + start + ") -- " + range.length + " bytes.");
            
            post.setEntity(EntityBuilder.create().setBinary(range).build());

            try (CloseableHttpResponse response = api.getClient().execute(post)) {
                int resultCode = response.getStatusLine().getStatusCode();
                String content = EntityUtils.toString(response.getEntity());
                log.info("Result of part " + i + ": " + content);
                
                post.releaseConnection();
                response.close();
                
                if (resultCode != 200 && resultCode != 201) {
                    throw new IllegalStateException("Failed uploading video (" + resultCode + "): " + content);
                }
                
            }
            
        }
        
        return new StatusResult("ok");
    }
}
 
开发者ID:brunocvcunha,项目名称:instagram4j,代码行数:71,代码来源:InstagramUploadVideoJobRequest.java


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