4

The documentation here says that setRequestProperty sets the general request property.

So suppose I have the following code snippet showing the usage of setRequestProperty as follows:

        URL url = new URL(requestUrl);
        URLConnection urlConn = url.openConnection();
        urlConn.setRequestProperty("accept", "application/json");
        urlConn.setRequestProperty("datetime", dateTimeString);
        urlConn.setRequestProperty("authorization", authorization);
        urlConn.setUseCaches(false);
        urlConn.setDoInput(true); // Triggers POST

Q1: Does accept need to have an uppercase A here? Similarly, for authorization, does it need to have an uppercase A as well? The reason I am asking this is because I have seen many post where people have been using authorization as say for example conn.setRequestProperty ("Authorization", "Basic " + encodedString);. This is shown here.

Q2. Since I have lot of setRequestProperty property defined above, does this means that, a URL contains all of these properties? Are there any other properties that exists besides the one I have used above?

Community
  • 1
  • 1
John
  • 1,210
  • 5
  • 23
  • 51

1 Answers1

4

A1: HTTP header fields, which include general-header (section 4.5), request-header (section 5.3), response-header (section 6.2), and entity-header (section 7.1) fields, follow the same generic format as that given in Section 3.1 of RFC 822 [9]. Each header field consists of a name followed by a colon (":") and the field value. Field names are case-insensitive.

A2: These variables will be in the HTTP request header. If you want URL contains these parameters, you need to append them on the URL:

http://www.google.com?bar=far&boo=foo
sendon1982
  • 9,982
  • 61
  • 44