mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-26 02:14:22 +00:00
Added http status code access for URL::createInputStream(). Also added threading + header display to the demo's http page.
This commit is contained in:
parent
14a5fcf410
commit
4889822eaf
11 changed files with 205 additions and 132 deletions
|
|
@ -589,10 +589,34 @@ public final class JuceAppActivity extends Activity
|
|||
//==============================================================================
|
||||
public static class HTTPStream
|
||||
{
|
||||
public HTTPStream (HttpURLConnection connection_) throws IOException
|
||||
public HTTPStream (HttpURLConnection connection_,
|
||||
int[] statusCode, StringBuffer responseHeaders) throws IOException
|
||||
{
|
||||
connection = connection_;
|
||||
inputStream = new BufferedInputStream (connection.getInputStream());
|
||||
|
||||
try
|
||||
{
|
||||
inputStream = new BufferedInputStream (connection.getInputStream());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
if (connection.getResponseCode() < org.apache.http.HttpStatus.SC_BAD_REQUEST)
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
statusCode[0] = connection.getResponseCode();
|
||||
}
|
||||
|
||||
if (statusCode[0] >= org.apache.http.HttpStatus.SC_BAD_REQUEST)
|
||||
inputStream = connection.getErrorStream();
|
||||
else
|
||||
inputStream = connection.getInputStream();
|
||||
|
||||
for (java.util.Map.Entry<String, java.util.List<String>> entry : connection.getHeaderFields().entrySet())
|
||||
if (entry.getKey() != null && entry.getValue() != null)
|
||||
responseHeaders.append (entry.getKey() + ": "
|
||||
+ android.text.TextUtils.join (",", entry.getValue()) + "\n");
|
||||
}
|
||||
|
||||
public final void release()
|
||||
|
|
@ -634,30 +658,31 @@ public final class JuceAppActivity extends Activity
|
|||
private long position;
|
||||
}
|
||||
|
||||
public static final HTTPStream createHTTPStream (String address, boolean isPost, byte[] postData,
|
||||
String headers, int timeOutMs,
|
||||
java.lang.StringBuffer responseHeaders)
|
||||
public static final HTTPStream createHTTPStream (String address,
|
||||
boolean isPost, byte[] postData, String headers,
|
||||
int timeOutMs, int[] statusCode,
|
||||
StringBuffer responseHeaders)
|
||||
{
|
||||
try
|
||||
{
|
||||
HttpURLConnection connection = (HttpURLConnection) (new URL (address).openConnection());
|
||||
|
||||
HttpURLConnection connection = (HttpURLConnection) (new URL(address)
|
||||
.openConnection());
|
||||
if (connection != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (isPost)
|
||||
{
|
||||
connection.setConnectTimeout (timeOutMs);
|
||||
connection.setDoOutput (true);
|
||||
connection.setChunkedStreamingMode (0);
|
||||
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setConnectTimeout(timeOutMs);
|
||||
connection.setDoOutput(true);
|
||||
connection.setChunkedStreamingMode(0);
|
||||
OutputStream out = connection.getOutputStream();
|
||||
out.write (postData);
|
||||
out.write(postData);
|
||||
out.flush();
|
||||
}
|
||||
|
||||
return new HTTPStream (connection);
|
||||
return new HTTPStream (connection, statusCode, responseHeaders);
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
|
|
@ -665,8 +690,7 @@ public final class JuceAppActivity extends Activity
|
|||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable e)
|
||||
{}
|
||||
catch (Throwable e) {}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue