mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Merge pull request #42 from dfg-nota/bugfix/http
Fix Async.Http HEAD and DELETE on Android
This commit is contained in:
@@ -164,8 +164,9 @@ public class Async
|
|||||||
|
|
||||||
public static class Http
|
public static class Http
|
||||||
{
|
{
|
||||||
private static final String DeleteMethod = "DELETE";
|
private static final String DELETE_METHOD = "DELETE";
|
||||||
private static final String GetMethod = "GET";
|
private static final String GET_METHOD = "GET";
|
||||||
|
private static final String HEAD_METHOD = "HEAD";
|
||||||
private static CookieManager cookieManager;
|
private static CookieManager cookieManager;
|
||||||
|
|
||||||
public static class KeyValuePair
|
public static class KeyValuePair
|
||||||
@@ -399,7 +400,7 @@ public class Async
|
|||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
|
||||||
// set the request method
|
// set the request method
|
||||||
String requestMethod = options.method != null ? options.method.toUpperCase(Locale.ENGLISH) : GetMethod;
|
String requestMethod = options.method != null ? options.method.toUpperCase(Locale.ENGLISH) : GET_METHOD;
|
||||||
connection.setRequestMethod(requestMethod);
|
connection.setRequestMethod(requestMethod);
|
||||||
|
|
||||||
// add the headers
|
// add the headers
|
||||||
@@ -412,7 +413,7 @@ public class Async
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Do not attempt to write the content (body) for DELETE method, Java will throw directly
|
// Do not attempt to write the content (body) for DELETE method, Java will throw directly
|
||||||
if (requestMethod != DeleteMethod)
|
if (!requestMethod.equals(DELETE_METHOD))
|
||||||
{
|
{
|
||||||
options.writeContent(connection, openedStreams);
|
options.writeContent(connection, openedStreams);
|
||||||
}
|
}
|
||||||
@@ -425,7 +426,10 @@ public class Async
|
|||||||
|
|
||||||
// build the result
|
// build the result
|
||||||
result.getHeaders(connection);
|
result.getHeaders(connection);
|
||||||
|
if (!requestMethod.equals(HEAD_METHOD))
|
||||||
|
{
|
||||||
result.readResponseStream(connection, openedStreams, options);
|
result.readResponseStream(connection, openedStreams, options);
|
||||||
|
}
|
||||||
|
|
||||||
// close the opened streams (saves copy-paste implementation
|
// close the opened streams (saves copy-paste implementation
|
||||||
// in each method that throws IOException)
|
// in each method that throws IOException)
|
||||||
|
|||||||
Reference in New Issue
Block a user