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


Java HttpPost.setURI方法代码示例

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


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

示例1: postOverrideContentType

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
@Test public void postOverrideContentType() throws Exception {
  server.enqueue(new MockResponse());

  HttpPost httpPost = new HttpPost();
  httpPost.setURI(server.url("/").url().toURI());
  httpPost.addHeader("Content-Type", "application/xml");
  httpPost.setEntity(new StringEntity("<yo/>"));
  client.execute(httpPost);

  RecordedRequest request = server.takeRequest();
  assertEquals(request.getHeader("Content-Type"), "application/xml");
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:OkApacheClientTest.java

示例2: updateMember

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
/**
 * Update a subscription to a group given a blank {@link Subscription}
 * object with only the updated
 * fields set.
 * Example:
 * 
 * <pre>
 * final Subscription subToUpdate = new Subscription();
 * subToUpdate.setAutoFollowReplies(true);
 * final Subscription updateSub = client.member().updateMember(subToUpdate);
 * </pre>
 * 
 * @param subscription
 *            - with only the updated fields set
 * @return the full {@link Subscription} after a successful update
 * @throws URISyntaxException
 * @throws IOException
 * @throws GroupsIOApiException
 */
public Subscription updateMember(final Subscription subscription) throws URISyntaxException, IOException, GroupsIOApiException
{
    if (apiClient.group().getPermissions(subscription.getGroupId()).getManageMemberSubscriptionOptions())
    {
        final URIBuilder uri = new URIBuilder().setPath(baseUrl + "updatemember");
        final HttpPost request = new HttpPost();
        final Map<String, Object> map = OM.convertValue(subscription, Map.class);
        final List<BasicNameValuePair> postParameters = new ArrayList<>();
        for (final Entry<String, Object> entry : map.entrySet())
        {
            postParameters.add(new BasicNameValuePair(entry.getKey(), entry.getValue().toString()));
        }
        request.setEntity(new UrlEncodedFormEntity(postParameters));
        
        request.setURI(uri.build());
        
        return callApi(request, Subscription.class);
    }
    else
    {
        final Error error = new Error();
        error.setType(GroupsIOApiExceptionType.INADEQUATE_PERMISSIONS);
        throw new GroupsIOApiException(error);
    }
}
 
开发者ID:lake54,项目名称:groupsio-api-java,代码行数:45,代码来源:MemberResource.java

示例3: updateGroup

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
/**
 * Update a group given a blank {@link Group} object with only the updated
 * fields set.
 * Example:
 * 
 * <pre>
 * final Group groupToUpdate = new Group();
 * groupToUpdate.setWebsite("https://github.com/lake54/groupsio-api-java");
 * final Group updatedGroup = client.group().updateGroup(groupToUpdate);
 * </pre>
 * 
 * @param group
 *            - with only the updated fields set
 * @return the full {@link Group} after a successful update
 * @throws URISyntaxException
 * @throws IOException
 * @throws GroupsIOApiException
 */
public Group updateGroup(final Group group) throws URISyntaxException, IOException, GroupsIOApiException
{
    if (apiClient.group().getPermissions(group.getId()).getManageGroupSettings())
    {
        final URIBuilder uri = new URIBuilder().setPath(baseUrl + "updategroup");
        final HttpPost request = new HttpPost();
        final Map<String, Object> map = OM.convertValue(group, Map.class);
        final List<BasicNameValuePair> postParameters = new ArrayList<>();
        for (final Entry<String, Object> entry : map.entrySet())
        {
            postParameters.add(new BasicNameValuePair(entry.getKey(), entry.getValue().toString()));
        }
        request.setEntity(new UrlEncodedFormEntity(postParameters));
        
        request.setURI(uri.build());
        
        return callApi(request, Group.class);
    }
    else
    {
        final Error error = new Error();
        error.setType(GroupsIOApiExceptionType.INADEQUATE_PERMISSIONS);
        throw new GroupsIOApiException(error);
    }
}
 
开发者ID:lake54,项目名称:groupsio-api-java,代码行数:44,代码来源:GroupResource.java

示例4: getPostResponse

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
private HttpResponse getPostResponse(String apiUrl, HttpPost httpPost) throws IOException {
	try{
		List<NameValuePair> nvps = new ArrayList<NameValuePair>();
		String[] urlAndParame = apiUrl.split("\\?");
		String apiUrlNoParame = urlAndParame[0];
		
		Map<String, String> parameMap = StrUtil.splitUrlToParameMap(apiUrl);
		
		nvps = paramsConverter(parameMap);

		httpPost.setURI(new URI(apiUrlNoParame));
		if(reqHeader != null) {
			Iterator<String> iterator = reqHeader.keySet().iterator();
			while(iterator.hasNext()) {
				String key = iterator.next();
				httpPost.addHeader(key, reqHeader.get(key));
			}
		}
		httpPost.setEntity(new UrlEncodedFormEntity(nvps, postDataEncode));
		return httpClient.execute(httpPost);
	}catch(Exception e){
    	throw new IllegalStateException(e);
    }
}
 
开发者ID:fier-liu,项目名称:FCat,代码行数:25,代码来源:HttpCallSSL.java

示例5: responseContentUri

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
public static String responseContentUri(URI uri) throws Exception {
    HttpClient client = new DefaultHttpClient();
    HttpPost request = new HttpPost();
    request.setURI(uri);
    InputStream is = client.execute(request).getEntity().getContent();
    BufferedReader inb = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder("");
    String line;
    String NL = System.getProperty("line.separator");
    while ((line = inb.readLine()) != null) {
        sb.append(line).append(NL);
    }
    inb.close();
    return sb.toString();
}
 
开发者ID:Suhas010,项目名称:Artificial-Intelligent-chat-bot-,代码行数:16,代码来源:NetworkUtils.java

示例6: 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

示例7: updateUser

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
/**
 * Update a user given a blank {@link User} object with only the updated
 * fields set.
 * Example:
 * 
 * <pre>
 * final User userToUpdate = new User();
 * userToUpdate.setPerPagePref("user_per_page_pref50");
 * final User updatedUser = client.user().updateUser(userToUpdate);
 * </pre>
 * 
 * @param user
 *            - with only the updated fields set
 * @return the full {@link User} after a successful update
 * @throws URISyntaxException
 * @throws IOException
 * @throws GroupsIOApiException
 */
public User updateUser(final User user) throws URISyntaxException, IOException, GroupsIOApiException
{
    final URIBuilder uri = new URIBuilder().setPath(baseUrl + "updateuser");
    final HttpPost request = new HttpPost();
    final Map<String, Object> map = OM.convertValue(user, Map.class);
    final List<BasicNameValuePair> postParameters = new ArrayList<>();
    for (final Entry<String, Object> entry : map.entrySet())
    {
        postParameters.add(new BasicNameValuePair(entry.getKey(), entry.getValue().toString()));
    }
    request.setEntity(new UrlEncodedFormEntity(postParameters));
    
    request.setURI(uri.build());
    
    return callApi(request, User.class);
}
 
开发者ID:lake54,项目名称:groupsio-api-java,代码行数:35,代码来源:UserResource.java

示例8: uploadFileByByte

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
@Override
public String uploadFileByByte(String fileUrl, byte[] fileByte, String requestParamInputName) throws IllegalStateException {
	HttpResponse response = null;
	HttpPost httpPost = getHttpPost();
	try {
		List<BasicNameValuePair> nvps = new ArrayList<BasicNameValuePair>();
		String[] urlAndParame = fileUrl.split("\\?");
		String apiUrlNoParame = urlAndParame[0];
		Map<String, String> parameMap = StrUtil.splitUrlToParameMap(fileUrl);
		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)));
		}
		// 多文件上传 获取文件数组前台标签name值
		if (!StrUtil.isBlank(requestParamInputName)) {
			multipartEntity.addPart("filesName", new StringBody(requestParamInputName, ContentType.create("text/plain", Consts.UTF_8)));
		}

		multipartEntity.addBinaryBody(requestParamInputName, fileByte);
		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,代码行数:46,代码来源:HttpCallSSL.java


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