private static HttpPost createRequest( String stationCode, String captchaText, String captchaId, VechileType type, String previous) { stationCode = toSumcCode(stationCode); String urlSuffix = String.format( "?%s=%s&%s=%s&%s=%s", QUERY_BUS_STOP_ID, stationCode, QUERY_O, "1", QUERY_GO, "1"); if (type != null) { urlSuffix += ("&" + VECHILE_TYPE_PARAMETER_NAME + "=" + type.ordinal()); } final HttpPost result = new HttpPost(URL + urlSuffix); result.addHeader("User-Agent", USER_AGENT); result.addHeader("Referer", REFERER); // Issue 85: // result.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true); try { final UrlEncodedFormEntity entity = new UrlEncodedFormEntity(parameters(stationCode, captchaText, captchaId, type, previous)); result.setEntity(entity); } catch (UnsupportedEncodingException e) { throw new IllegalStateException("Not supported default encoding?", e); } return result; }
private static List<BasicNameValuePair> parameters( String stationCode, String captchaText, String captchaId, VechileType type, String previous) { final List<BasicNameValuePair> result = new ArrayList<BasicNameValuePair>(6); if (previous != null) { final Map<String, String> parametersMapping = getParametersMapping(previous, stationCode, captchaText, captchaId); parametersMapping.put("submit", "Провери"); for (Entry<String, String> next : parametersMapping.entrySet()) { result.add(new BasicNameValuePair(next.getKey(), next.getValue())); } if (type != null) { result.add( createParameter( parametersMapping, VECHILE_TYPE_PARAMETER_NAME, Integer.toString(type.ordinal()))); } } return result; }