java类org.apache.http.message.BasicNameValuePair的实例源码

HttpClientStack.java 文件源码 项目:publicProject 阅读 32 收藏 0 点赞 0 评论 0
@SuppressWarnings("unused")
private static List<NameValuePair> getPostParameterPairs(Map<String, String> postParams) {
    List<NameValuePair> result = new ArrayList<NameValuePair>(postParams.size());
    for (String key : postParams.keySet()) {
        result.add(new BasicNameValuePair(key, postParams.get(key)));
    }
    return result;
}
PlayRecordApi.java 文件源码 项目:letv 阅读 31 收藏 0 点赞 0 评论 0
@Deprecated
public String s_sendMobile(int updataId, String mobile, String ver, String Cookid) {
    String requestUrl;
    if (PreferencesManager.getInstance().isTestApi() && LetvConfig.isForTest()) {
        requestUrl = "http://test2.m.letv.com/android/dynamic.php";
    } else {
        requestUrl = "http://dynamic.user.app.m.letv.com/android/dynamic.php";
    }
    String str = MD5.toMd5("action=reg&mobile=" + mobile + "&pcode=" + LetvConfig.getPcode() + "&plat=mobile_tv" + "&version=" + LetvUtils.getClientVersionName() + "&poi345");
    List<BasicNameValuePair> list = new ArrayList();
    list.add(new BasicNameValuePair("mod", MODIFYPWD_PARAMETERS.MOD_VALUE));
    list.add(new BasicNameValuePair("ctl", "clientSendMsg"));
    list.add(new BasicNameValuePair(SocialConstants.PARAM_ACT, "index"));
    list.add(new BasicNameValuePair("mobile", mobile));
    list.add(new BasicNameValuePair(MODIFYPWD_PARAMETERS.PLAT_KEY, "mobile_tv"));
    list.add(new BasicNameValuePair(MODIFYPWD_PARAMETERS.APISIGN_KEY, str));
    list.add(new BasicNameValuePair("action", "reg"));
    list.add(new BasicNameValuePair("captchaValue", ver));
    list.add(new BasicNameValuePair("captchaId", Cookid));
    list.add(new BasicNameValuePair("pcode", LetvConfig.getPcode()));
    list.add(new BasicNameValuePair("version", LetvUtils.getClientVersionName()));
    Log.e("ZSM", "s_sendMobile url == " + ParameterBuilder.getQueryUrl(list, requestUrl));
    return ParameterBuilder.getQueryUrl(list, requestUrl);
}
ServerUtil.java 文件源码 项目:Higher-Cloud-Computing-Project 阅读 34 收藏 0 点赞 0 评论 0
public static String register(String email_addr, String nick_name, String pwd) throws Exception {

        HttpClient task_post = new DefaultHttpClient();
        HttpPost post = new HttpPost(url + "/Register");
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("email_addr", email_addr));
        params.add(new BasicNameValuePair("nick_name", nick_name));
        params.add(new BasicNameValuePair("pwd", pwd));
        post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
        HttpResponse response = task_post.execute(post);
        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            String result = null;
            HttpEntity httpEntity = response.getEntity();
            if (httpEntity != null) {
                result = EntityUtils.toString(httpEntity);
            }
            JSONObject jsonObject = new JSONObject(result);
            int register_status = jsonObject.getInt("register_status");
            int user_id = jsonObject.getInt("user_id");
            if (register_status == 1)
                return "SUCCESS,your user_id is " + String.valueOf(user_id);
            else
                return "FAIL";
        }
        return "401 UNAUTHORIZED";
    }
UserCenterApi.java 文件源码 项目:letv 阅读 33 收藏 0 点赞 0 评论 0
public String getChatRecords(String roomId, boolean server, String tm, int mode) {
    String keyb = roomId + "," + tm + "," + LetvConstant.CHAT_KEY;
    ArrayList<BasicNameValuePair> params = new ArrayList();
    params.add(new BasicNameValuePair("luamod", "main"));
    params.add(new BasicNameValuePair("mod", HOME_RECOMMEND_PARAMETERS.MOD_VALUE));
    params.add(new BasicNameValuePair("ctl", "chatGethistory"));
    params.add(new BasicNameValuePair(SocialConstants.PARAM_ACT, "index"));
    params.add(new BasicNameValuePair("roomId", roomId));
    params.add(new BasicNameValuePair("server", String.valueOf(server)));
    params.add(new BasicNameValuePair("tm", tm));
    params.add(new BasicNameValuePair("key", MD5.toMd5(keyb)));
    params.add(new BasicNameValuePair("pcode", LetvConfig.getPcode()));
    if (mode == 0) {
        params.add(new BasicNameValuePair("version", LetvUtils.getClientVersionName()));
    } else {
        params.add(new BasicNameValuePair("version", "6.0"));
    }
    LogInfo.log("clf", "获取历史聊天记录requestChatRecords..url=" + ParameterBuilder.getQueryUrl(params, getDynamicUrl()));
    return ParameterBuilder.getQueryUrl(params, getDynamicUrl());
}
HttpUtils.java 文件源码 项目:elasticjob-stock-push 阅读 59 收藏 0 点赞 0 评论 0
/**
 * post form
 *
 * @param host
 * @param path
 * @param method
 * @param headers
 * @param querys
 * @param bodys
 * @return
 * @throws Exception
 */
public static HttpResponse doPost(String host, String path, String method,
                                  Map<String, String> headers,
                                  Map<String, String> querys,
                                  Map<String, String> bodys)
        throws Exception {
    HttpClient httpClient = wrapClient(host);

    HttpPost request = new HttpPost(buildUrl(host, path, querys));
    for (Map.Entry<String, String> e : headers.entrySet()) {
        request.addHeader(e.getKey(), e.getValue());
    }

    if (bodys != null) {
        List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();

        for (String key : bodys.keySet()) {
            nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key)));
        }
        UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8");
        formEntity.setContentType("application/x-www-form-urlencoded");

        request.setEntity(formEntity);
    }

    return httpClient.execute(request);
}
SessionMananger.java 文件源码 项目:mxisd 阅读 29 收藏 0 点赞 0 评论 0
private void submitRemote(ThreePidSession session, String token) {
    UrlEncodedFormEntity entity = new UrlEncodedFormEntity(
            Arrays.asList(
                    new BasicNameValuePair("sid", session.getRemoteId()),
                    new BasicNameValuePair("client_secret", session.getRemoteSecret()),
                    new BasicNameValuePair("token", token)
            ), StandardCharsets.UTF_8);
    HttpPost submitReq = new HttpPost(session.getRemoteServer() + "/_matrix/identity/api/v1/submitToken");
    submitReq.setEntity(entity);

    try (CloseableHttpResponse response = client.execute(submitReq)) {
        JsonObject o = new GsonParser().parse(response.getEntity().getContent());
        if (!o.has("success") || !o.get("success").getAsBoolean()) {
            String errcode = o.get("errcode").getAsString();
            throw new RemoteIdentityServerException(errcode + ": " + o.get("error").getAsString());
        }

        log.info("Successfully submitted validation token for {} to {}", session.getThreePid(), session.getRemoteServer());
    } catch (IOException e) {
        throw new RemoteIdentityServerException(e.getMessage());
    }
}
PlayRecordApi.java 文件源码 项目:letv 阅读 25 收藏 0 点赞 0 评论 0
public static String requestPraiseInfo(int updataId) {
    String baseUrl = getUserDynamicUrl();
    String uid = LetvUtils.getUID();
    String userName = LetvUtils.getLoginUserName();
    String deviceId = LetvUtils.generateDeviceId(BaseApplication.getInstance());
    StringBuilder md5Sb = new StringBuilder();
    md5Sb.append("uid=" + uid + "&");
    md5Sb.append("username=" + userName + "&");
    md5Sb.append("devid=" + deviceId + "&");
    md5Sb.append("pcode=" + LetvConfig.getPcode() + "&");
    md5Sb.append("version=" + LetvUtils.getClientVersionName() + "&");
    md5Sb.append("letvpraise2014");
    String md5Sign = MD5.toMd5(md5Sb.toString());
    ArrayList<BasicNameValuePair> params = new ArrayList();
    params.add(new BasicNameValuePair("mod", "passport"));
    params.add(new BasicNameValuePair("ctl", "index"));
    params.add(new BasicNameValuePair(SocialConstants.PARAM_ACT, "praiseactivity"));
    params.add(new BasicNameValuePair("uid", uid));
    params.add(new BasicNameValuePair("username", userName));
    params.add(new BasicNameValuePair(HOME_RECOMMEND_PARAMETERS.DEVICEID_KEY, deviceId));
    params.add(new BasicNameValuePair("pcode", LetvConfig.getPcode()));
    params.add(new BasicNameValuePair("version", LetvUtils.getClientVersionName()));
    params.add(new BasicNameValuePair(TradeInfo.SIGN, md5Sign));
    return ParameterBuilder.getQueryUrl(params, baseUrl);
}
PlayRecordApi.java 文件源码 项目:letv 阅读 35 收藏 0 点赞 0 评论 0
public String deletePlayTraces(int updataId, String pid, String vid, String uid, String idstr, String flush, String backdata, String sso_tk) {
    String baseUrl = UrlConstdata.getDynamicUrl();
    List<BasicNameValuePair> list = new ArrayList();
    list.add(new BasicNameValuePair("mod", "minfo"));
    list.add(new BasicNameValuePair("ctl", "cloud"));
    list.add(new BasicNameValuePair(SocialConstants.PARAM_ACT, "del"));
    list.add(new BasicNameValuePair("pid", pid));
    list.add(new BasicNameValuePair("vid", vid));
    list.add(new BasicNameValuePair("uid", uid));
    list.add(new BasicNameValuePair("idstr", idstr));
    list.add(new BasicNameValuePair("flush", flush));
    list.add(new BasicNameValuePair("backdata", backdata));
    list.add(new BasicNameValuePair("sso_tk", sso_tk));
    list.add(new BasicNameValuePair("pcode", LetvHttpApiConfig.PCODE));
    list.add(new BasicNameValuePair("version", LetvHttpApiConfig.VERSION));
    return ParameterBuilder.getQueryUrl(list, baseUrl);
}
MyResourcesApiTest.java 文件源码 项目:Equella 阅读 32 收藏 0 点赞 0 评论 0
private JsonNode doMyResourcesSearch(String query, String subsearch, Map<?, ?> otherParams, String token)
    throws Exception
{
    List<NameValuePair> params = Lists.newArrayList();
    if( query != null )
    {
        params.add(new BasicNameValuePair("q", query));
    }
    for( Entry<?, ?> entry : otherParams.entrySet() )
    {
        params.add(new BasicNameValuePair(entry.getKey().toString(), entry.getValue().toString()));
    }
    // params.add(new BasicNameValuePair("token",
    // TokenSecurity.createSecureToken(username, "token", "token", null)));
    String paramString = URLEncodedUtils.format(params, "UTF-8");
    HttpGet get = new HttpGet(context.getBaseUrl() + "api/search/myresources/" + subsearch + "?" + paramString);
    HttpResponse response = execute(get, false, token);
    return mapper.readTree(response.getEntity().getContent());
}
ServerUtil.java 文件源码 项目:Higher-Cloud-Computing-Project 阅读 32 收藏 0 点赞 0 评论 0
/**
 * send current ip to server
 */
private String ipSend() throws Exception {
    HttpClient ip_send = new DefaultHttpClient();
    HttpPost post = new HttpPost(url + "/UploadIP");
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("machine_id", String.valueOf(machine_id)));
    params.add(new BasicNameValuePair("ip", ip));
    post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
    HttpResponse httpResponse = ip_send.execute(post);
    if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        String result = null;
        HttpEntity httpEntity = httpResponse.getEntity();
        if (httpEntity != null) {
            result = EntityUtils.toString(httpEntity);
        }
        JSONObject jsonObject = new JSONObject(result);
        int ip_save = jsonObject.getInt("ip_save");
        if (ip_save == 1) {
            return "SUCCESS";
        } else return "FAIL";
    }
    return "401 UNAUTHORIZED";
}
PlayRecordApi.java 文件源码 项目:letv 阅读 32 收藏 0 点赞 0 评论 0
public String loginWeixin(int updataId, String accessToken, String openId, String plat, String equipType, String equipID, String softID, String pcode, String version) {
    String baseUrl = UrlConstdata.getDynamicUrl();
    List<BasicNameValuePair> list = new ArrayList();
    list.add(new BasicNameValuePair("luamod", "main"));
    list.add(new BasicNameValuePair("mod", HOME_RECOMMEND_PARAMETERS.MOD_VALUE));
    list.add(new BasicNameValuePair("ctl", "appssoweixin"));
    list.add(new BasicNameValuePair(SocialConstants.PARAM_ACT, "index"));
    list.add(new BasicNameValuePair("access_token", accessToken));
    list.add(new BasicNameValuePair("openid", openId));
    list.add(new BasicNameValuePair(MODIFYPWD_PARAMETERS.PLAT_KEY, plat));
    list.add(new BasicNameValuePair("equipID", equipID));
    list.add(new BasicNameValuePair("softID", softID));
    list.add(new BasicNameValuePair("pcode", pcode));
    list.add(new BasicNameValuePair("version", version));
    list.add(new BasicNameValuePair("imei", LetvUtils.getIMEI()));
    list.add(new BasicNameValuePair("mac", LetvUtils.getMacAddressForLogin()));
    return ParameterBuilder.getQueryUrl(list, baseUrl);
}
LetvUrlMaker.java 文件源码 项目:letv 阅读 29 收藏 0 点赞 0 评论 0
public static String getAlbumByTimeUrl(String year, String month, String id, String videoType) {
    String head = getStaticHead() + "/mod/mob/ctl/videolistbydate/act/detail";
    String end = LetvHttpApiConfig.getStaticEnd();
    ArrayList<BasicNameValuePair> params = new ArrayList();
    params.add(new BasicNameValuePair("version", LetvUtils.getClientVersionName()));
    params.add(new BasicNameValuePair("pcode", LetvUtils.getPcode()));
    if (!TextUtils.isEmpty(year)) {
        params.add(new BasicNameValuePair("year", year));
    }
    if (!TextUtils.isEmpty(month)) {
        params.add(new BasicNameValuePair("month", month));
    }
    params.add(new BasicNameValuePair("id", id));
    if (!TextUtils.isEmpty(videoType)) {
        params.add(new BasicNameValuePair(PlayConstant.VIDEO_TYPE, videoType));
    }
    return ParameterBuilder.getPathUrl(params, head, end);
}
ServerUtil.java 文件源码 项目:Higher-Cloud-Computing-Project 阅读 41 收藏 0 点赞 0 评论 0
public static String resetPwd(int user_id, String pwd) throws Exception {

        HttpClient task_post = new DefaultHttpClient();
        HttpPost post = new HttpPost(url + "/ResetPwd");
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("user_id", String.valueOf(user_id)));
        params.add(new BasicNameValuePair("pwd", pwd));
        post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
        HttpResponse response = task_post.execute(post);
        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            String result = null;
            HttpEntity httpEntity = response.getEntity();
            if (httpEntity != null) {
                result = EntityUtils.toString(httpEntity);
            }
            JSONObject jsonObject = new JSONObject(result);
            int pwd_reset = jsonObject.getInt("pwd_reset");
            if (pwd_reset == 1)
                return "SUCCESS";
            else
                return "FAIL";
        }
        return "401 UNAUTHORIZED";
    }
HTTPClient.java 文件源码 项目:boohee_v5.6 阅读 38 收藏 0 点赞 0 评论 0
public String PostConnect(String httpUrl, String str) {
    String resultData = "";
    HttpPost httpPost = new HttpPost(httpUrl);
    List<NameValuePair> params = new ArrayList();
    params.add(new BasicNameValuePair("data", str));
    try {
        httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
        HttpResponse httpResponse = new DefaultHttpClient().execute(httpPost);
        if (httpResponse.getStatusLine().getStatusCode() == 200) {
            resultData = EntityUtils.toString(httpResponse.getEntity());
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e2) {
        e2.printStackTrace();
    } catch (IOException e3) {
        e3.printStackTrace();
    }
    return resultData;
}
LetvUrlMaker.java 文件源码 项目:letv 阅读 28 收藏 0 点赞 0 评论 0
public static String getAlbumByTimeUrl(String year, String month, String id, String videoType) {
    String head = getStaticHead() + "/mod/mob/ctl/videolistbydate/act/detail";
    String end = LetvHttpApiConfig.getStaticEnd();
    ArrayList<BasicNameValuePair> params = new ArrayList();
    params.add(new BasicNameValuePair("version", LetvUtils.getClientVersionName()));
    params.add(new BasicNameValuePair("pcode", LetvUtils.getPcode()));
    if (!TextUtils.isEmpty(year)) {
        params.add(new BasicNameValuePair("year", year));
    }
    if (!TextUtils.isEmpty(month)) {
        params.add(new BasicNameValuePair("month", month));
    }
    params.add(new BasicNameValuePair("id", id));
    if (!TextUtils.isEmpty(videoType)) {
        params.add(new BasicNameValuePair(PlayConstant.VIDEO_TYPE, videoType));
    }
    return ParameterBuilder.getPathUrl(params, head, end);
}
FormEncodedBody.java 文件源码 项目:rest-client 阅读 34 收藏 0 点赞 0 评论 0
private List<NameValuePair> getList(Map<String, List<Object>> parameters) {
    List<NameValuePair> result = new ArrayList<NameValuePair>();
    if (parameters != null) {
        TreeMap<String, List<Object>> sortedParameters = new TreeMap<String, List<Object>>(parameters);
        for (Map.Entry<String, List<Object>> entry : sortedParameters.entrySet()) {
            List<Object> entryValue = entry.getValue();
            if (entryValue != null) {
                for (Object cur : entryValue) {
                    if (cur != null) {
                        result.add(new BasicNameValuePair(entry.getKey(), cur.toString()));
                    }
                }
            }
        }
    }
    return result;
}
A6OrderAty.java 文件源码 项目:Huochexing12306 阅读 34 收藏 0 点赞 0 评论 0
private List<OrderDBInfo> queryMyOrderNoComplete(BookingInfo bInfo) {
    String url = "https://kyfw.12306.cn/otn/queryOrder/queryMyOrderNoComplete";
    List<NameValuePair> lstParams = new ArrayList<NameValuePair>();
    lstParams.add(new BasicNameValuePair("_json_att", ""));
    try {
        A6Info a6Json = A6Util
                .post(bInfo,
                        A6Util.makeRefererColl("https://kyfw.12306.cn/otn/queryOrder/initNoComplete"),
                        url, lstParams);
        if ("".equals(a6Json.getData())) {
            return (new ArrayList<OrderDBInfo>());
        } else {
            int index1 = a6Json.getData().indexOf("[");
            int index2 = a6Json.getData().lastIndexOf("]") + 1;
            String strOrderDBList = a6Json.getData().substring(index1,
                    index2);
            List<OrderDBInfo> lstODBInfos = A6Util.getGson().fromJson(
                    strOrderDBList, new TypeToken<List<OrderDBInfo>>() {
                    }.getType());
            return lstODBInfos;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
ServerUtil.java 文件源码 项目:Higher-Cloud-Computing-Project 阅读 30 收藏 0 点赞 0 评论 0
public static String active(int user_id, String verification_code) throws Exception {
    HttpClient task_post = new DefaultHttpClient();
    HttpPost post = new HttpPost(url + "/Active");
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("user_id", String.valueOf(user_id)));
    params.add(new BasicNameValuePair("verification_code", verification_code));
    post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
    HttpResponse response = task_post.execute(post);
    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        String result = null;
        HttpEntity httpEntity = response.getEntity();
        if (httpEntity != null) {
            result = EntityUtils.toString(httpEntity);
        }
        JSONObject jsonObject = new JSONObject(result);
        int email_verification = jsonObject.getInt("email_verification");
        if (email_verification == 1)
            return "SUCCESS";
        else
            return "FAIL";
    }
    return "401 UNAUTHORIZED";
}
MainActivity.java 文件源码 项目:android-advanced-light 阅读 26 收藏 0 点赞 0 评论 0
private void useHttpClientPost(String url) {
    HttpPost mHttpPost = new HttpPost(url);
    mHttpPost.addHeader("Connection", "Keep-Alive");
    try {
        HttpClient mHttpClient = createHttpClient();
        List<NameValuePair> postParams = new ArrayList<>();
        //要传递的参数
        postParams.add(new BasicNameValuePair("ip", "59.108.54.37"));
        mHttpPost.setEntity(new UrlEncodedFormEntity(postParams));
        HttpResponse mHttpResponse = mHttpClient.execute(mHttpPost);
        HttpEntity mHttpEntity = mHttpResponse.getEntity();
        int code = mHttpResponse.getStatusLine().getStatusCode();
        if (null != mHttpEntity) {
            InputStream mInputStream = mHttpEntity.getContent();
            String respose = converStreamToString(mInputStream);
            Log.d(TAG, "请求状态码:" + code + "\n请求结果:\n" + respose);
            mInputStream.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
RestClient.java 文件源码 项目:httpclient 阅读 31 收藏 0 点赞 0 评论 0
@SuppressWarnings("unchecked")
private HttpEntity createDataEntity(Object data) {
    try {
        if (data instanceof Map) {
            List<NameValuePair> params = new ArrayList<NameValuePair>(0);
            for (Entry<String, Object> entry : ((Map<String, Object>) data).entrySet()) {
                params.add(new BasicNameValuePair(entry.getKey(), entry.getValue().toString()));
            }
            return new UrlEncodedFormEntity(params, "UTF-8");
        } else {
            return new StringEntity(data.toString(), "UTF-8");
        }
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("Unsupported encoding noticed. Error message: " + e.getMessage());
    }
}
PlayRecordApi.java 文件源码 项目:letv 阅读 27 收藏 0 点赞 0 评论 0
public String loginSina(int updataId, String accessToken, String openId, String plat, String equipType, String equipID, String softID, String pcode, String version) {
    String baseUrl = UrlConstdata.getDynamicUrl();
    List<BasicNameValuePair> list = new ArrayList();
    list.add(new BasicNameValuePair("luamod", "main"));
    list.add(new BasicNameValuePair("mod", HOME_RECOMMEND_PARAMETERS.MOD_VALUE));
    list.add(new BasicNameValuePair("ctl", "appssosina"));
    list.add(new BasicNameValuePair(SocialConstants.PARAM_ACT, "index"));
    list.add(new BasicNameValuePair("access_token", accessToken));
    list.add(new BasicNameValuePair("uid", openId));
    list.add(new BasicNameValuePair(MODIFYPWD_PARAMETERS.PLAT_KEY, plat));
    list.add(new BasicNameValuePair("equipType", equipType));
    list.add(new BasicNameValuePair("equipID", equipID));
    list.add(new BasicNameValuePair("pcode", pcode));
    list.add(new BasicNameValuePair("softID", softID));
    list.add(new BasicNameValuePair("version", version));
    list.add(new BasicNameValuePair("imei", LetvUtils.getIMEI()));
    list.add(new BasicNameValuePair("mac", LetvUtils.getMacAddressForLogin()));
    return ParameterBuilder.getQueryUrl(list, baseUrl);
}
ListSmsCallbackEventRequest.java 文件源码 项目:smn-sdk-java 阅读 40 收藏 0 点赞 0 评论 0
/**
 * obtain the get request param
 *
 * @return the param string
 */
private String getRequestParamString() {
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    if (!StringUtils.isBlank(eventType)) {
        nameValuePairs.add(new BasicNameValuePair(SmnConstants.EVENT_TYPE, eventType));
    }

    String param = "";
    if (!nameValuePairs.isEmpty()) {
        try {
            param = EntityUtils.toString(new UrlEncodedFormEntity(nameValuePairs, Charset.forName("UTF-8")));
        } catch (IOException e) {
            throw new RuntimeException("get request param error");
        }
    }
    return param;
}
HttpUtils.java 文件源码 项目:elasticjob-oray-client 阅读 49 收藏 0 点赞 0 评论 0
/**
 * post form
 *
 * @param host
 * @param path
 * @param method
 * @param headers
 * @param querys
 * @param bodys
 * @return
 * @throws Exception
 */
public static HttpResponse doPost(String host, String path, String method,
                                  Map<String, String> headers,
                                  Map<String, String> querys,
                                  Map<String, String> bodys)
        throws Exception {
    HttpClient httpClient = wrapClient(host);

    HttpPost request = new HttpPost(buildUrl(host, path, querys));
    for (Map.Entry<String, String> e : headers.entrySet()) {
        request.addHeader(e.getKey(), e.getValue());
    }

    if (bodys != null) {
        List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();

        for (String key : bodys.keySet()) {
            nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key)));
        }
        UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8");
        formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
        request.setEntity(formEntity);
    }

    return httpClient.execute(request);
}
PlayRecordApi.java 文件源码 项目:letv 阅读 55 收藏 0 点赞 0 评论 0
public String requestTicketUrl(int updataId, String userId, String days) {
    String baseUrl;
    if (PreferencesManager.getInstance().isTestApi() && LetvConfig.isForTest()) {
        baseUrl = "http://t.api.mob.app.letv.com/yuanxian/myTickets?";
    } else {
        baseUrl = "http://api.mob.app.letv.com/yuanxian/myTickets?";
    }
    List<BasicNameValuePair> list = new ArrayList();
    list.add(new BasicNameValuePair("uid", userId));
    list.add(new BasicNameValuePair("days", days));
    list.add(new BasicNameValuePair("mac", LetvUtils.getMacAddress()));
    list.add(new BasicNameValuePair("pcode", LetvConfig.getPcode()));
    list.add(new BasicNameValuePair("version", LetvUtils.getClientVersionName()));
    Log.e("ZSM", "requestTicketUrl url == " + ParameterBuilder.getQueryUrl(list, baseUrl));
    return ParameterBuilder.getQueryUrl(list, baseUrl);
}
HttpUtil.java 文件源码 项目:FaceDistinguish 阅读 30 收藏 0 点赞 0 评论 0
/**
 * 构建FormEntity
 * 
 * @param formParam
 * @return
 * @throws UnsupportedEncodingException
 */
private static UrlEncodedFormEntity buildFormEntity(Map<String, String> formParam)
        throws UnsupportedEncodingException {
    if (formParam != null) {
        List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();

        for (String key : formParam.keySet()) {
            nameValuePairList.add(new BasicNameValuePair(key, formParam.get(key)));
        }
        UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, Constants.ENCODING);
        formEntity.setContentType(ContentType.CONTENT_TYPE_FORM);
        return formEntity;
    }

    return null;
}
RequestParams.java 文件源码 项目:android-project-gallery 阅读 33 收藏 0 点赞 0 评论 0
protected List<BasicNameValuePair> getParamsList() {
    List<BasicNameValuePair> lparams = new LinkedList<BasicNameValuePair>();

    for (ConcurrentHashMap.Entry<String, String> entry : urlParams.entrySet()) {
        lparams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
    }

    lparams.addAll(getParamsList(null, urlParamsWithObjects));

    return lparams;
}
URIBuilder.java 文件源码 项目:lams 阅读 37 收藏 0 点赞 0 评论 0
/**
 * Sets parameter of URI query overriding existing value if set. The parameter name and value
 * are expected to be unescaped and may contain non ASCII characters.
 */
public URIBuilder setParameter(final String param, final String value) {
    if (this.queryParams == null) {
        this.queryParams = new ArrayList<NameValuePair>();
    }
    if (!this.queryParams.isEmpty()) {
        for (Iterator<NameValuePair> it = this.queryParams.iterator(); it.hasNext(); ) {
            NameValuePair nvp = it.next();
            if (nvp.getName().equals(param)) {
                it.remove();
            }
        }
    }
    this.queryParams.add(new BasicNameValuePair(param, value));
    this.encodedQuery = null;
    this.encodedSchemeSpecificPart = null;
    return this;
}
ServerUtil.java 文件源码 项目:Higher-Cloud-Computing-Project 阅读 32 收藏 0 点赞 0 评论 0
public String update_online_time(int machine_id, int user_id, int delta) throws Exception {

        HttpClient task_post = new DefaultHttpClient();
        HttpPost post = new HttpPost(url + "/update_online_time");
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("machine_id", String.valueOf(machine_id)));
        params.add(new BasicNameValuePair("user_id", String.valueOf(user_id)));
        params.add(new BasicNameValuePair("delta", String.valueOf(delta)));
        post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
        HttpResponse response = task_post.execute(post);
        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
//        权限通过
            return "AUTHORIZED";
        }
        return "401 UNAUTHORIZED";
    }
WebServer.java 文件源码 项目:momo-2 阅读 29 收藏 0 点赞 0 评论 0
/**
 * Perform an Oauth2 callback to the Discord servers with the token given by the user's approval
 * @param token Token from user
 * @param res Passed on response
 * @throws ClientProtocolException Error in HTTP protocol
 * @throws IOException Encoding exception or error in protocol
 * @throws NoAPIKeyException No API keys set
 */
static void oauth(String token, Response res) throws ClientProtocolException, IOException, NoAPIKeyException {

    CloseableHttpClient httpclient = HttpClients.createDefault();

    HttpPost post = new HttpPost("https://discordapp.com/api/oauth2/token");
    List<NameValuePair> nvp = new ArrayList<NameValuePair>();
    nvp.add(new BasicNameValuePair("client_id", Bot.getInstance().getApiKeys().get("dashboardid")));
    nvp.add(new BasicNameValuePair("client_secret", Bot.getInstance().getApiKeys().get("dashboardsecret")));
    nvp.add(new BasicNameValuePair("grant_type", "authorization_code"));
    nvp.add(new BasicNameValuePair("code", token));

    post.setEntity(new UrlEncodedFormEntity(nvp));

    String accessToken;
    CloseableHttpResponse response = httpclient.execute(post);
    try {
        System.out.println(response.getStatusLine());
        HttpEntity entity = response.getEntity();
        JsonObject authJson;
        try(BufferedReader buffer = new BufferedReader(new InputStreamReader(entity.getContent()))) {
            authJson = Json.parse(buffer.lines().collect(Collectors.joining("\n"))).asObject();
        }
        accessToken = authJson.getString("access_token", "");
        EntityUtils.consume(entity);
        getGuilds(res, accessToken);
    } finally {
        response.close();
    }
}
A6OrderAty.java 文件源码 项目:Huochexing12306 阅读 36 收藏 0 点赞 0 评论 0
private boolean returnTicket(BookingInfo bInfo) {
    String url = "https://kyfw.12306.cn/otn/queryOrder/returnTicket";
    List<NameValuePair> lstParams = new ArrayList<NameValuePair>();
    lstParams.add(new BasicNameValuePair("_json_att", ""));
    try {
        String strHtml = bInfo
                .getHttpHelper()
                .post(A6Util
                        .makeRefererColl("https://kyfw.12306.cn/otn/queryOrder/init"),
                        url, lstParams);
        if (strHtml != null && strHtml.indexOf("退票成功") > 0) {
            return true;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}


问题


面经


文章

微信
公众号

扫码关注公众号