Answer the question
In order to leave comments, you need to log in
HttpURLConnection does not work on Android versions older than Lollipop. Where is the mistake?
Good afternoon!
I'm trying to send an Http request using HttpUrlConnection:
DataOutputStream wr;
URL obj = new URL(url);
con = (HttpsURLConnection) obj.openConnection();
con.setConnectTimeout(5000);
con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", USER_AGENT);
con.setRequestProperty("Content-Type", "audio/x-pcm;bit=" + bit + ";rate=" +ar.getSampleRate());
con.setRequestProperty("Transfer-Encoding", "chunked");
con.setDoOutput(true);
wr = new DataOutputStream(con.getOutputStream());
ArrayList<byte[]> Data = new ArrayList<>();
while (isRecording) {
ar.read(sData, 0, bufferSize / 2);
byte bData[] = short2byte(sData);
Data.add(bData);
os.write(bData, 0, bufferSize);
wr.write(bData, 0, bufferSize);
}
os.flush();
os.close();
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
Answer the question
In order to leave comments, you need to log in
I think it's a problem with USER-AGENT. Try to use the full line of the existing one and add your own at the end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question