added default content type

This commit is contained in:
Pablo Fernandez committed 2011-09-25 19:14:57 -03:00
1 parent 24babbae02
commit ae3a1b11c9
3 files changed
+52 -1

No files matched your search

@@ -17,6 +17,8 @@ import org.scribe.utils.*;
class Request
{
private static final String CONTENT_LENGTH = "Content-Length";
private static final String CONTENT_TYPE = "Content-Type";
public static final String DEFAULT_CONTENT_TYPE = "application/x-www-form-urlencoded";
private String url;
private Verb verb;
@@ -108,6 +110,12 @@ class Request
void addBody(HttpURLConnection conn, byte[] content) throws IOException
{
conn.setRequestProperty(CONTENT_LENGTH, String.valueOf(content.length));
// Set default content type if none is set.
if (conn.getRequestProperty(CONTENT_TYPE) == null)
{
conn.setRequestProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE);
}
conn.setDoOutput(true);
conn.getOutputStream().write(content);
}