类org.apache.http.Consts源码实例Demo

下面列出了怎么用org.apache.http.Consts的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: ticket   文件: ApiRequestService.java
public boolean isLogin(UserModel userModel) {
    HttpUtil httpUtil = UserTicketStore.httpUtilStore.get(userModel.getUsername());
    HttpPost httpPost = new HttpPost(apiConfig.getUamtkStatic());
    List<NameValuePair> formparams = new ArrayList<>();
    formparams.add(new BasicNameValuePair("appid", "otn"));
    UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(formparams,
            Consts.UTF_8);
    httpPost.setEntity(urlEncodedFormEntity);
    String response = httpUtil.post(httpPost);
    Gson jsonResult = new Gson();
    Map rsmap = jsonResult.fromJson(response, Map.class);
    if ("0.0".equals(rsmap.get("result_code").toString())) {
        userModel.setUamtk(rsmap.get("newapptk").toString());
        UserTicketStore.httpUtilStore.put(userModel.getUsername(), httpUtil);
        return true;
    } else {
        return false;
    }
}
 
源代码2 项目: ticket   文件: ApiRequestService.java
public String uamtk(String userName) {
    HttpUtil httpUtil = UserTicketStore.httpUtilStore.get(userName);
    HttpPost httpPost = new HttpPost(apiConfig.getUamtk());
    List<NameValuePair> formparams = new ArrayList<>();
    formparams.add(new BasicNameValuePair("appid", "otn"));
    UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(formparams,
            Consts.UTF_8);
    httpPost.setEntity(urlEncodedFormEntity);
    Gson jsonResult = new Gson();
    String response = httpUtil.post(httpPost);
    Map rsmap = jsonResult.fromJson(response, Map.class);
    if ("0.0".equals(rsmap.getOrDefault("result_code", "").toString())) {
        UserTicketStore.httpUtilStore.put(userName, httpUtil);
        return rsmap.get("newapptk").toString();
    }
    return null;
}
 
源代码3 项目: ticket   文件: ApiRequestService.java
public List<PassengerModel> getPassengerDTOs(String userName, String token) {
    HttpUtil httpUtil = UserTicketStore.httpUtilStore.get(userName);
    List<PassengerModel> passengerModelList = new ArrayList<>();
    HttpPost httpPost = new HttpPost(apiConfig.getGetPassengerDTOs());
    List<NameValuePair> formparams = new ArrayList<>();
    formparams.add(new BasicNameValuePair("_json_att", ""));
    formparams.add(new BasicNameValuePair("REPEAT_SUBMIT_TOKEN", token));
    UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(formparams,
            Consts.UTF_8);
    httpPost.setEntity(urlEncodedFormEntity);
    Gson jsonResult = new Gson();
    String response = httpUtil.post(httpPost);
    Map rsmap = jsonResult.fromJson(response, Map.class);
    if (rsmap.getOrDefault("status", "").toString().equals("true")) {
        rsmap = (Map<String, Object>) rsmap.get("data");
        List<Map<String, String>> passengers = (List<Map<String, String>>) rsmap
                .get("normal_passengers");
        if (!CollectionUtils.isEmpty(passengers)) {
            passengers.forEach(passenger -> {
                PassengerModel passengerModel = new PassengerModel(passenger);
                passengerModelList.add(passengerModel);
            });
        }
    }
    return passengerModelList;
}
 
源代码4 项目: ticket   文件: ApiRequestService.java
public boolean checkRandCodeAnsyn(String position, String token) {
    HttpUtil httpUtil = new HttpUtil();
    HttpPost httpPost = new HttpPost(apiConfig.getCheckRandCodeAnsyn());
    List<NameValuePair> formparams = new ArrayList<>();
    formparams.add(new BasicNameValuePair("randCode", position));
    formparams.add(new BasicNameValuePair("REPEAT_SUBMIT_TOKEN", token));
    formparams.add(new BasicNameValuePair("rand", "randp"));
    UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(formparams,
            Consts.UTF_8);
    httpPost.setEntity(urlEncodedFormEntity);
    String response = httpUtil.post(httpPost);

    Gson jsonResult = new Gson();
    Map rsmap = jsonResult.fromJson(response, Map.class);
    if (rsmap.getOrDefault("status", "").toString().equals("true")) {
        return true;
    }
    log.error("验证码错误", rsmap.get("result_message"));
    return false;
}
 
源代码5 项目: clouddisk   文件: ClassTest.java
public static void main(String args[]){
    HttpClient httpClient = HttpClients.createDefault();
    HttpPost httpPost = new HttpPost("http://localhost:8080/sso-web/upload");
    httpPost.addHeader("Range","bytes=10000-");
    final MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
    multipartEntity.setCharset(Consts.UTF_8);
    multipartEntity.setMode(HttpMultipartMode.STRICT);
    multipartEntity.addBinaryBody("file", new File("/Users/huanghuanlai/Desktop/test.java"));
    httpPost.setEntity(multipartEntity.build());
    try {
        HttpResponse response = httpClient.execute(httpPost);

    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
源代码6 项目: xiaoV   文件: MessageTools.java
/**
 * 消息发送
 *
 * @param msgType
 * @param content
 * @param toUserName
 * @author https://github.com/yaphone
 * @date 2017年4月23日 下午2:32:02
 */
public static void webWxSendMsg(int msgType, String content,
		String toUserName) {
	String url = String.format(URLEnum.WEB_WX_SEND_MSG.getUrl(), core
			.getLoginInfo().get("url"));
	Map<String, Object> msgMap = new HashMap<String, Object>();
	msgMap.put("Type", msgType);
	msgMap.put("Content", content);
	msgMap.put("FromUserName", core.getUserName());
	msgMap.put("ToUserName", toUserName == null ? core.getUserName()
			: toUserName);
	msgMap.put("LocalID", new Date().getTime() * 10);
	msgMap.put("ClientMsgId", new Date().getTime() * 10);
	Map<String, Object> paramMap = core.getParamMap();
	paramMap.put("Msg", msgMap);
	paramMap.put("Scene", 0);
	try {
		String paramStr = JSON.toJSONString(paramMap);
		HttpEntity entity = myHttpClient.doPost(url, paramStr);
		EntityUtils.toString(entity, Consts.UTF_8);
	} catch (Exception e) {
		LOG.error("webWxSendMsg", e);
	}
}
 
源代码7 项目: xiaoV   文件: WechatTools.java
private static boolean webWxLogout() {
	String url = String.format(URLEnum.WEB_WX_LOGOUT.getUrl(), core
			.getLoginInfo().get(StorageLoginInfoEnum.url.getKey()));
	List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
	params.add(new BasicNameValuePair("redirect", "1"));
	params.add(new BasicNameValuePair("type", "1"));
	params.add(new BasicNameValuePair("skey", (String) core.getLoginInfo()
			.get(StorageLoginInfoEnum.skey.getKey())));
	try {
		HttpEntity entity = core.getMyHttpClient().doGet(url, params,
				false, null);
		String text = EntityUtils.toString(entity, Consts.UTF_8); // 无消息
		return true;
	} catch (Exception e) {
		LOG.debug(e.getMessage());
	}
	return false;
}
 
源代码8 项目: xiaoV   文件: LoginServiceImpl.java
@Override
public void wxStatusNotify() {
	// 组装请求URL和参数
	String url = String.format(URLEnum.STATUS_NOTIFY_URL.getUrl(), core
			.getLoginInfo().get(StorageLoginInfoEnum.pass_ticket.getKey()));

	Map<String, Object> paramMap = core.getParamMap();
	paramMap.put(StatusNotifyParaEnum.CODE.para(),
			StatusNotifyParaEnum.CODE.value());
	paramMap.put(StatusNotifyParaEnum.FROM_USERNAME.para(),
			core.getUserName());
	paramMap.put(StatusNotifyParaEnum.TO_USERNAME.para(),
			core.getUserName());
	paramMap.put(StatusNotifyParaEnum.CLIENT_MSG_ID.para(),
			System.currentTimeMillis());
	String paramStr = JSON.toJSONString(paramMap);

	try {
		HttpEntity entity = httpClient.doPost(url, paramStr);
		EntityUtils.toString(entity, Consts.UTF_8);
	} catch (Exception e) {
		LOG.error("微信状态通知接口失败!", e);
	}

}
 
源代码9 项目: android-uiconductor   文件: HttpProxyUtils.java
public static String postRequestAsString(String url, String request)
    throws UicdDeviceHttpConnectionResetException {
  logger.info("post request to xmldumper:" + url);
  String ret = "";
  Response response = null;
  try {
    response = Request.Post(url)
        .body(new StringEntity(request))
        .execute();
    ret = response.returnContent().asString(Consts.UTF_8);
  } catch (IOException e) {
    logger.severe(e.getMessage());
    // See comments in getRequestAsString
    if (CONNECTION_RESET_KEYWORDS_LIST.stream().parallel().anyMatch(e.getMessage()::contains)) {
      throw new UicdDeviceHttpConnectionResetException(e.getMessage());
    }
  }
  logger.info("return from xmldumper:" + ret);
  return ret;
}
 
源代码10 项目: julongchain   文件: CouchDB.java
/**
 * WarmIndex method provides a function for warming a single index
 * @param designdoc
 * @param indexname
 * @return
 */
public Boolean warmIndex(CouchDbClient db, String designdoc,String indexname){
    Boolean boolFalg = false;
    try {
        List<NameValuePair> params = Lists.newArrayList();
        params.add(new BasicNameValuePair("stale", "update_after"));
        String paramStr = EntityUtils.toString(new UrlEncodedFormEntity(params, Consts.UTF_8));

        String str = String.format("_design/%s/_view/%s?" + paramStr, designdoc, indexname);
        URI build = URIBuilderUtil.buildUri(db.getDBUri()).path(str).build();
        HttpGet get = new HttpGet(build);
        HttpResponse response = db.executeRequest(get);
        int code = response.getStatusLine().getStatusCode();
        if (code == 200){
            boolFalg = true;
        }
    } catch (Exception e) {
        boolFalg = false;
        e.printStackTrace();
    }
    return boolFalg;
}
 
源代码11 项目: DataLink   文件: HttpClientUtil.java
public String executeAndGet(HttpRequestBase httpRequestBase) throws Exception {
    HttpResponse response;
    String entiStr = "";
    try {
        response = httpClient.execute(httpRequestBase);

        if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            System.err.println("请求地址:" + httpRequestBase.getURI() + ", 请求方法:" + httpRequestBase.getMethod()
                    + ",STATUS CODE = " + response.getStatusLine().getStatusCode());

            throw new Exception("Response Status Code : " + response.getStatusLine().getStatusCode());
        } else {
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                entiStr = EntityUtils.toString(entity, Consts.UTF_8);
            } else {
                throw new Exception("Response Entity Is Null");
            }
        }
    } catch (Exception e) {
        throw e;
    }

    return entiStr;
}
 
源代码12 项目: clouddisk   文件: FileUploadParser.java
public HttpPost initRequest(final FileUploadParameter parameter) {
	final FileUploadAddress fileUploadAddress = getDependResult(FileUploadAddress.class);
	final HttpPost request = new HttpPost("http://" + fileUploadAddress.getData().getUp() + CONST.URI_PATH);
	final MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
	multipartEntity.setCharset(Consts.UTF_8);
	multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
	multipartEntity.addPart(CONST.QID_NAME, new StringBody(getLoginInfo().getQid(), ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("ofmt", new StringBody("json", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("method", new StringBody("Upload.web", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("token", new StringBody(readCookieStoreValue("token"), ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("v", new StringBody("1.0.1", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("tk", new StringBody(fileUploadAddress.getData().getTk(), ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("Upload", new StringBody("Submit Query", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("devtype", new StringBody("web", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("pid", new StringBody("ajax", ContentType.DEFAULT_BINARY));
	multipartEntity.addPart("Filename",
			new StringBody(parameter.getUploadFile().getName(), ContentType.APPLICATION_JSON));
	multipartEntity.addPart("path", new StringBody(parameter.getPath(), ContentType.APPLICATION_JSON));// 解决中文不识别问题
	multipartEntity.addBinaryBody("file", parameter.getUploadFile());
	request.setEntity(multipartEntity.build());
	return request;
}
 
源代码13 项目: document-management-software   文件: HttpRestWb.java
private static void createFolderSimpleJSON(CloseableHttpClient httpclient)
			throws UnsupportedEncodingException, IOException {

//		CloseableHttpClient httpclient = HttpClients.createDefault();

		// This will create a tree starting from the Default workspace
		String folderPath = "/Default/USA/NJ/Fair Lawn/createSimple/JSON";
		String input = "{ \"folderPath\" : \"" + folderPath + "\" }";
		System.out.println(input);

		HttpPost httppost = new HttpPost(BASE_PATH + "/services/rest/folder/createSimpleJSON");
		StringEntity entity = new StringEntity(input, ContentType.create("application/json", Consts.UTF_8));
		httppost.setEntity(entity);

		CloseableHttpResponse response = httpclient.execute(httppost);
		try {
			HttpEntity rent = response.getEntity();
			if (rent != null) {
				String respoBody = EntityUtils.toString(rent, "UTF-8");
				System.out.println(respoBody);
			}
		} finally {
			response.close();
		}
	}
 
源代码14 项目: sofa-rpc   文件: RestDataBindingTest.java
@Test
public void testForm() throws IOException {
    Assert.assertEquals("form", restService.bindForm("form"));

    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost("http://127.0.0.1:8803/rest/bindForm");

    List<NameValuePair> list = new ArrayList<NameValuePair>();
    list.add(new BasicNameValuePair("formP", "formBBB"));
    HttpEntity httpEntity = new UrlEncodedFormEntity(list, Consts.UTF_8);

    httpPost.setEntity(httpEntity);

    HttpResponse httpResponse = httpclient.execute(httpPost);
    String result = EntityUtils.toString(httpResponse.getEntity());

    Assert.assertEquals("formBBB", result);
}
 
源代码15 项目: chatbot   文件: QANARY.java
private String makeRequest(String question) {
        try {
            HttpPost httpPost = new HttpPost(URL);
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("query", question));
//            params.add(new BasicNameValuePair("lang", "it"));
            params.add(new BasicNameValuePair("kb", "dbpedia"));

            UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, Consts.UTF_8);
            httpPost.setEntity(entity);

            HttpResponse response = client.execute(httpPost);

            // Error Scenario
            if(response.getStatusLine().getStatusCode() >= 400) {
                logger.error("QANARY Server could not answer due to: " + response.getStatusLine());
                return null;
            }

            return EntityUtils.toString(response.getEntity());
        }
        catch(Exception e) {
            logger.error(e.getMessage());
        }
        return null;
    }
 
源代码16 项目: simple-sso   文件: HTTPUtil.java
/**
 * 向目标url发送post请求
 * 
 * @author sheefee
 * @date 2017年9月12日 下午5:10:36
 * @param url
 * @param params
 * @return boolean
 */
public static boolean post(String url, Map<String, String> params) {
	CloseableHttpClient httpclient = HttpClients.createDefault();
	HttpPost httpPost = new HttpPost(url);
	// 参数处理
	if (params != null && !params.isEmpty()) {
		List<NameValuePair> list = new ArrayList<NameValuePair>();
		
		Iterator<Entry<String, String>> it = params.entrySet().iterator();
		while (it.hasNext()) {
			Entry<String, String> entry = it.next();
			list.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
		}
		
		httpPost.setEntity(new UrlEncodedFormEntity(list, Consts.UTF_8));
	}
	// 执行请求
	try {
		CloseableHttpResponse response = httpclient.execute(httpPost);
		response.getStatusLine().getStatusCode();
	} catch (Exception e) {
		e.printStackTrace();
	}
	return true;
}
 
源代码17 项目: clouddisk   文件: FileUploadAddressParser.java
public HttpPost initRequest(final FileUploadAddressParameter parameter) {
	final HttpPost request = new HttpPost(getRequestUri());
	final List<NameValuePair> data = new ArrayList<>(1);
	data.add(new BasicNameValuePair(CONST.AJAX_KEY, CONST.AJAX_VAL));
	request.setEntity(new UrlEncodedFormEntity(data, Consts.UTF_8));
	return request;
}
 
源代码18 项目: AthenaServing   文件: HttpFluentService.java
private String executeGet(String url, String hostName, Integer port, String schemeName, Map<String, String> paramMap) {
    Args.notNull(url, "url");

    url = buildGetParam(url, paramMap);
    Request request = Request.Get(url);
    request = buildProxy(request, hostName, port, schemeName);
    try {
        return request.execute().returnContent().asString(Consts.UTF_8);
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e.toString());
    }
    return null;
}
 
源代码19 项目: clouddisk   文件: FileAddFileParser.java
@Override
public HttpPost initRequest(final FileAddFileParameter parameter) {
	final HttpPost request = new HttpPost(getRequestUri());
	final List<NameValuePair> data = new ArrayList<>(2);
	data.add(new BasicNameValuePair(CONST.TK_NAME, parameter.getTk()));
	data.add(new BasicNameValuePair(CONST.AJAX_KEY, CONST.AJAX_VAL));
	request.setEntity(new UrlEncodedFormEntity(data, Consts.UTF_8));
	return request;
}
 
源代码20 项目: AthenaServing   文件: HttpFluentService.java
private String executePost(String url, String hostName, Integer port, String schemeName, List<NameValuePair> nameValuePairs, List<File> files) {
    Args.notNull(url, "url");
    HttpEntity entity = buildPostParam(nameValuePairs, files);
    Request request = Request.Post(url).body(entity);
    request = buildProxy(request, hostName, port, schemeName);
    try {
        return request.execute().returnContent().asString(Consts.UTF_8);
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e.toString());
    }
    return null;
}
 
源代码21 项目: clouddisk   文件: UserSigninParser.java
@Override
public HttpPost initRequest(final UserSigninParameter parameter) {
	final HttpPost request = new HttpPost(getRequestUri());
	final List<NameValuePair> data = new ArrayList<>(4);
	data.add(new BasicNameValuePair(CONST.AJAX_KEY, CONST.AJAX_VAL));
	data.add(new BasicNameValuePair(CONST.METHOD_KEY, UserSizeConst.METHOD_VAL));
	data.add(new BasicNameValuePair("t", TimeUtil.getTimeLenth(10)));
	request.setEntity(new UrlEncodedFormEntity(data, Consts.UTF_8));
	return request;
}
 
源代码22 项目: ticket   文件: ApiRequestService.java
public boolean login(UserModel userModel) {
    HttpUtil httpUtil = UserTicketStore.httpUtilStore.get(userModel.getUsername());
    HttpPost httpPost = new HttpPost(apiConfig.getLogin());
    List<NameValuePair> formparams = new ArrayList<>();
    formparams.add(new BasicNameValuePair("username", userModel.getUsername()));
    formparams.add(new BasicNameValuePair("password", userModel.getPassword()));
    formparams.add(new BasicNameValuePair("appid", "otn"));
    formparams.add(new BasicNameValuePair("answer", userModel.getAnswer()));

    UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(formparams,
            Consts.UTF_8);
    httpPost.setEntity(urlEncodedFormEntity);
    String response = httpUtil.post(httpPost);
    if (StringUtils.isEmpty(response)) {
        log.error("登录失败!");
        return false;
    }
    Gson jsonResult = new Gson();
    Map rsmap = jsonResult.fromJson(response, Map.class);
    if (!"0.0".equals(rsmap.getOrDefault("result_code", "").toString())) {
        log.error("登陆失败:{}", rsmap);
        return false;
    }
    UserTicketStore.httpUtilStore.put(userModel.getUsername(), httpUtil);
    userModel.setUamtk(rsmap.get("uamtk").toString());
    return true;
}
 
源代码23 项目: clouddisk   文件: FileDownloadAddressParser.java
@Override
public HttpPost initRequest(final FileDownloadAddressParameter parameter) {
	final HttpPost request = new HttpPost(getRequestUri());
	final List<NameValuePair> data = new ArrayList<>(3);
	data.add(new BasicNameValuePair(CONST.NID_NAME, parameter.getNid()));
	data.add(new BasicNameValuePair(CONST.FNAME_NAME, parameter.getFname()));
	data.add(new BasicNameValuePair(CONST.AJAX_KEY, CONST.AJAX_VAL));
	request.setEntity(new UrlEncodedFormEntity(data, Consts.UTF_8));
	return request;
}
 
源代码24 项目: cos-java-sdk-v4   文件: DefaultCosHttpClient.java
private void setMultiPartEntity(HttpPost httpPost, Map<String, String> params)
        throws Exception {
    ContentType utf8TextPlain = ContentType.create("text/plain", Consts.UTF_8);
    MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
    for (String paramKey : params.keySet()) {
        if (paramKey.equals(RequestBodyKey.FILE_CONTENT)) {
            entityBuilder.addBinaryBody(RequestBodyKey.FILE_CONTENT, params
                    .get(RequestBodyKey.FILE_CONTENT).getBytes(Charset.forName("ISO-8859-1")));
        } else {
            entityBuilder.addTextBody(paramKey, params.get(paramKey), utf8TextPlain);
        }
    }
    httpPost.setEntity(entityBuilder.build());
}
 
源代码25 项目: clouddisk   文件: FileRecycleParser.java
@Override
public HttpPost initRequest(final FileRecycleParameter parameter) {
	final HttpPost request = new HttpPost(getRequestUri());
	final List<NameValuePair> data = new ArrayList<>(0);
	if (null != parameter.getPath()) {
		data.addAll(parameter.getPath().stream().map(pa -> new BasicNameValuePair(CONST.PATH_NAME, pa)).collect(Collectors.toList()));
	}
	data.add(new BasicNameValuePair(CONST.AJAX_KEY, CONST.AJAX_VAL));
	request.setEntity(new UrlEncodedFormEntity(data, Consts.UTF_8));
	return request;
}
 
源代码26 项目: japi   文件: JapiClientTransfer.java
private Result postValues(String url, List<String[]> datas) {
    HttpPost httpPost = new HttpPost(url);
    List<NameValuePair> valuePairs = new ArrayList<>();
    for (String[] keyValue : datas) {
        valuePairs.add(new BasicNameValuePair(keyValue[0], keyValue[1]));
    }
    Integer tryCount = 0;
    while (reties > tryCount) {
        try {
            httpPost.setEntity(new UrlEncodedFormEntity(valuePairs, "utf-8"));
            httpPost.setHeader("token", token);
            String result = EntityUtils.toString(HTTP_CLIENT.execute(httpPost).getEntity(), Consts.UTF_8);
            Result result1 = JSON.parseObject(result, ResultImpl.class);
            if (result1.getCode() != 0) {
                throw new JapiException(result1.getMsg());
            }
            return result1;
        } catch (IOException e) {
            if (e instanceof HttpHostConnectException) {
                tryCount++;
                LOGGER.warn("try connect server " + tryCount + " count.");
                try {
                    TimeUnit.SECONDS.sleep(tryTime);
                } catch (InterruptedException e1) {
                    e1.printStackTrace();
                }
            }
        }
    }
    if (tryCount <= reties) {
        LOGGER.error("server connect failed.");
    }
    return null;
}
 
源代码27 项目: xiaoV   文件: MessageTools.java
/**
 * 发送图片消息,内部调用
 *
 * @return
 * @author https://github.com/yaphone
 * @date 2017年5月7日 下午10:38:55
 */
private static boolean webWxSendMsgImg(String userId, String mediaId) {
	String url = String.format(
			"%s/webwxsendmsgimg?fun=async&f=json&pass_ticket=%s", core
					.getLoginInfo().get("url"),
			core.getLoginInfo().get("pass_ticket"));
	Map<String, Object> msgMap = new HashMap<String, Object>();
	msgMap.put("Type", 3);
	msgMap.put("MediaId", mediaId);
	msgMap.put("FromUserName", core.getUserSelf().getString("UserName"));
	msgMap.put("ToUserName", userId);
	String clientMsgId = String.valueOf(new Date().getTime())
			+ String.valueOf(new Random().nextLong()).substring(1, 5);
	msgMap.put("LocalID", clientMsgId);
	msgMap.put("ClientMsgId", clientMsgId);
	Map<String, Object> paramMap = core.getParamMap();
	paramMap.put("BaseRequest", core.getParamMap().get("BaseRequest"));
	paramMap.put("Msg", msgMap);
	String paramStr = JSON.toJSONString(paramMap);
	HttpEntity entity = myHttpClient.doPost(url, paramStr);
	if (entity != null) {
		try {
			String result = EntityUtils.toString(entity, Consts.UTF_8);
			return JSON.parseObject(result).getJSONObject("BaseResponse")
					.getInteger("Ret") == 0;
		} catch (Exception e) {
			LOG.error("webWxSendMsgImg 错误: ", e);
		}
	}
	return false;

}
 
源代码28 项目: xiaoV   文件: LoginServiceImpl.java
@Override
public void WebWxBatchGetContact() {
	String url = String.format(
			URLEnum.WEB_WX_BATCH_GET_CONTACT.getUrl(),
			core.getLoginInfo().get(StorageLoginInfoEnum.url.getKey()),
			new Date().getTime(),
			core.getLoginInfo().get(
					StorageLoginInfoEnum.pass_ticket.getKey()));
	Map<String, Object> paramMap = core.getParamMap();
	paramMap.put("Count", core.getGroupIdList().size());
	List<Map<String, String>> list = new ArrayList<Map<String, String>>();
	for (int i = 0; i < core.getGroupIdList().size(); i++) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("UserName", core.getGroupIdList().get(i));
		map.put("EncryChatRoomId", "");
		list.add(map);
	}
	paramMap.put("List", list);
	HttpEntity entity = httpClient.doPost(url, JSON.toJSONString(paramMap));
	try {
		String text = EntityUtils.toString(entity, Consts.UTF_8);
		JSONObject obj = JSON.parseObject(text);
		JSONArray contactList = obj.getJSONArray("ContactList");
		for (int i = 0; i < contactList.size(); i++) { // 群好友
			if (contactList.getJSONObject(i).getString("UserName")
					.indexOf("@@") > -1) { // 群
				core.getGroupNickNameList().add(
						contactList.getJSONObject(i).getString("NickName")); // 更新群昵称列表
				core.getGroupList().add(contactList.getJSONObject(i)); // 更新群信息(所有)列表
				core.getGroupMemeberMap().put(
						contactList.getJSONObject(i).getString("UserName"),
						contactList.getJSONObject(i).getJSONArray(
								"MemberList")); // 更新群成员Map
			}
		}
	} catch (Exception e) {
		LOG.info(e.getMessage());
	}
}
 
源代码29 项目: JavaWeb   文件: HttpGetPostRequestMokUtil.java
public static HttpResponse httpClientForPost(String url,String ip,List<NameValuePair> list,CloseableHttpClient closeableHttpClient) throws Exception {
HttpPost post = new HttpPost(url);
post.addHeader("x-forwarded-for", ip);
UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(list,Consts.UTF_8);
post.setEntity(urlEncodedFormEntity);
HttpResponse httpResponse = closeableHttpClient.execute(post);
return httpResponse;
  }
 
源代码30 项目: singleton   文件: HttpsUtils.java
private static String execute(HttpUriRequest request) throws Exception {
    CloseableHttpResponse response = httpsClientExe.execute(request);
    if (HttpStatus.SC_OK != response.getStatusLine().getStatusCode()) {
        throw new Exception("Invalid http status code:" + response.getStatusLine().getStatusCode());
    }
    return EntityUtils.toString(response.getEntity(), Consts.UTF_8);
}
 
 类所在包
 类方法
 同包方法