All pastes #991866 Raw Edit

Unbenannt

public text v1 · immutable
#991866 ·published 2008-04-21 13:13 UTC
rendered paste body
public static RequestInfo postRequest(URL url, String cookie, String referrer, HashMap<String, String> requestProperties, char[] parameter, boolean redirect) throws IOException {
        // logger.finer("post: "+link+"(cookie:"+cookie+" parameter:
        // "+parameter+")");
        long timer = System.currentTimeMillis();
        HTTPConnection httpConnection = new HTTPConnection(url.openConnection());
        httpConnection.setInstanceFollowRedirects(redirect);
        if (referrer != null)
            httpConnection.setRequestProperty("Referer", referrer);
        else
            httpConnection.setRequestProperty("Referer", "http://" + url.getHost());
        if (cookie != null) httpConnection.setRequestProperty("Cookie", cookie);
        // TODO das gleiche wie bei getRequest
        httpConnection.setRequestProperty("Accept-Language", ACCEPT_LANGUAGE);
        httpConnection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");
        if (requestProperties != null) {
            Set<String> keys = requestProperties.keySet();
            Iterator<String> iterator = keys.iterator();
            String key;
            while (iterator.hasNext()) {
                key = iterator.next();
                httpConnection.setRequestProperty(key, requestProperties.get(key));
            }
        }
        if (parameter != null) {
            httpConnection.setRequestProperty("Content-Length", parameter.length + "");
        }
        httpConnection.setDoOutput(true);
        httpConnection.connect();

        httpConnection.post(parameter);

        int responseCode = 0;
        try {
            responseCode = httpConnection.getResponseCode();
        } catch (IOException e) {
        }
        String location = httpConnection.getHeaderField("Location");
        String setcookie = getCookieString(httpConnection);
        RequestInfo requestInfo = new RequestInfo("", location, setcookie, httpConnection.getHeaderFields(), responseCode);

        requestInfo.setConnection(httpConnection);
        // logger.finer("postRequest " + url + ": " +
        // (System.currentTimeMillis() - timer) + " ms");
        return requestInfo;
    }