提交 0532dd9b 编写于 作者: C Collin Jackson

Merge pull request #2297 from collinjackson/content_type

Support for setting Content-Type of POST requests
......@@ -158,6 +158,17 @@ public class UrlLoaderImpl implements UrlLoader {
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) {
......@@ -186,19 +197,13 @@ public class UrlLoaderImpl implements UrlLoader {
}
}
} 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());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册