user6571062
user6571062

Reputation:

Content length is not printed

I'm trying to print all headers to check my request but unfortunately it prints all headers expect content-length why it doesn't print content length ? what the problem is ? here is my request

public static String performPostCall(String requestURL,
        String postDataParams, int length, PrintWriter pw) throws Exception {
    URL url;
    String response = "";
    try {
        url = new URL(requestURL);

        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setReadTimeout(10000);
        conn.setConnectTimeout(10000);
        conn.setRequestMethod("POST");

        conn.setRequestProperty("SOAPAction",
                "http://tempuri.org/SendRequest");
        conn.setRequestProperty(HTTP.CONTENT_TYPE,
                "text/xml; charset=utf-8");
        conn.setRequestProperty("Content-Length", String.valueOf(length));

        conn.setDoInput(true);
        conn.setDoOutput(true);
        pw.println("Post request: " + url);
        for (String header : conn.getRequestProperties().keySet()) {
            if (header != null) {
                for (String value : conn.getRequestProperties().get(header)) {
                    System.out.println(header + ":" + value);
                }
            }
        }
        pw.println(postDataParams);
    //code..

    return response;
}

Upvotes: 0

Views: 95

Answers (1)

user6077173
user6077173

Reputation:

I believe Content-Length is a header property that is automatically set based on the size of your request.

Upvotes: 1

Related Questions