public void start() { synchronized (mLock) { if (mCanceled) { return; } validateNotStarted(); validateNotRecycled(); mStarted = true; String method = mMethod; if (method == null && ((mPostBody != null && mPostBody.length > 0) || mPostBodyChannel != null)) { // Default to POST if there is data to upload but no method was // specified. method = "POST"; } if (method != null) { nativeSetMethod(mUrlRequestPeer, method); } if (mHeaders != null && !mHeaders.isEmpty()) { for (Entry<String, String> entry : mHeaders.entrySet()) { nativeAddHeader(mUrlRequestPeer, entry.getKey(), entry.getValue()); } } if (mAdditionalHeaders != null) { for (Entry<String, String> entry : mAdditionalHeaders.entrySet()) { nativeAddHeader(mUrlRequestPeer, entry.getKey(), entry.getValue()); } } if (mPostBody != null && mPostBody.length > 0) { nativeSetUploadData(mUrlRequestPeer, mPostBodyContentType, mPostBody); } else if (mPostBodyChannel != null) { nativeSetUploadChannel( mUrlRequestPeer, mPostBodyContentType, mPostBodyChannel, mUploadContentLength); } nativeStart(mUrlRequestPeer); } }