Skip to content

Commit

Permalink
Support for setting Content-Type of POST requests
Browse files Browse the repository at this point in the history
  • Loading branch information
collinjackson committed Jan 26, 2016
1 parent 6943977 commit e462b27
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions sky/services/oknet/src/org/domokit/oknet/UrlLoaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@ public void run() {
return;
}

Request.Builder builder = new Request.Builder().url(url);

String contentType = null;
if (mRequest.headers != null) {
for (HttpHeader header : mRequest.headers) {
if (header.name.toLowerCase().equals("content-type"))
contentType = header.value;
builder.addHeader(header.name, header.value);
}
}

RequestBody body = null;
if (mRequest.body != null && mRequest.body[0] != null) {
if (mRequest.body.length > 1) {
Expand Down Expand Up @@ -186,19 +197,13 @@ public void run() {
}
}
} while (true);
String contentType = "application/x-www-form-urlencoded; charset=utf8";
if (contentType == null)
contentType = "application/x-www-form-urlencoded; charset=utf8";
MediaType mediaType = MediaType.parse(contentType);
body = RequestBody.create(mediaType, bodyStream.toByteArray());
}

Request.Builder builder =
new Request.Builder().url(url).method(mRequest.method, body);

if (mRequest.headers != null) {
for (HttpHeader header : mRequest.headers) {
builder.addHeader(header.name, header.value);
}
}
builder.method(mRequest.method, body);

// TODO(abarth): responseBodyBufferSize, autoFollowRedirects, bypassCache.
Call call = mClient.newCall(builder.build());
Expand Down

0 comments on commit e462b27

Please sign in to comment.