use of java.net.CookieManager in project remusic by aa112901.
the class HttpUtil method postUrl.
public static void postUrl(Context context, String j) {
try {
String action = "https://music.163.com/weapi/login/";
RequestBody formBody = new FormEncodingBuilder().build();
Log.e("post", "p");
Request request = new Request.Builder().url(action).header("Content-Type", "application/x-www-form-urlencoded").header("Host", "music.163.com").header("Cookie", "appver=1.5.0.75771").header("Referer", "http://music.163.com/").header("Connection", "keep-alive").header("Accept-Encoding", "gzip,deflate").header("Accept", "*/*").header("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36").post(formBody).build();
mOkHttpClient.setCookieHandler(new CookieManager(new PersistentCookieStore(context.getApplicationContext()), CookiePolicy.ACCEPT_ALL));
Response response = mOkHttpClient.newCall(request).execute();
if (response.isSuccessful()) {
Log.e("respose", response.body().string());
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of java.net.CookieManager in project remusic by aa112901.
the class HttpUtil method postNetease.
public static void postNetease(Context context, String j) {
try {
String action = "https://music.163.com/weapi/login/";
RequestBody formBody = new FormEncodingBuilder().add("params", "9NdyZTlp0Q/f1E1ora4tGM0uLYXqh7MD0mk7632ilWQvRDPZ02UkHrGFUccwW4HZYpacpPnmE+oMr/HI/vhuQvg8zYKgDP6NOaXG8nKDJpQTfOAiXT5KDrJOvb7ejSj/").add("encSeckey", "ae878167c394a959699c025a5c36043d0ae043c42d7f55fe4d1191c8ac9f3abe285b78c4a25ed6d9394a0ba0cb83a9a62de697199bd337f1de183bb07d6764a051495ea873ad615bb0a7e69f44d9168fc78ed1d61feb142ad06679dce58257ee9005756a18032ff499a4e24f7658bb59de2219f21f568301d43dba500e0c2d3b").build();
String json = "{\"params\": \"9NdyZTlp0Q/f1E1ora4tGM0uLYXqh7MD0mk7632ilWQvRDPZ02UkHrGFUccwW4HZYpacpPnmE+oMr/HI/vhuQvg8zYKgDP6NOaXG8nKDJpQTfOAiXT5KDrJOvb7ejSj/\", " + "\"encSecKey\": \"ae878167c394a959699c025a5c36043d0ae043c42d7f55fe4d1191c8ac9f3abe285b78c4a25ed6d9394a0ba0cb83a9a62de697199bd337f1de183bb07d6764a051495ea873ad615bb0a7e69f44d9168fc78ed1d61feb142ad06679dce58257ee9005756a18032ff499a4e24f7658bb59de2219f21f568301d43dba500e0c2d3b\"}";
RequestBody requestBody = RequestBody.create(MediaType.parse("JSON"), json);
Log.e("post", "p");
Request request = new Request.Builder().url(action).header("Content-Type", "application/x-www-form-urlencoded").header("Host", "music.163.com").header("Cookie", "appver=1.5.0.75771").header("Referer", "http://music.163.com/").header("Connection", "keep-alive").header("Accept-Encoding", "gzip,deflate").header("Accept", "*/*").header("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36").post(requestBody).build();
mOkHttpClient.setCookieHandler(new CookieManager(new PersistentCookieStore(context.getApplicationContext()), CookiePolicy.ACCEPT_ALL));
Response response = mOkHttpClient.newCall(request).execute();
if (response.isSuccessful()) {
Log.e("respose", response.body().string());
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of java.net.CookieManager in project okhttp by square.
the class ResponseCacheTest method setUp.
@Before
public void setUp() throws Exception {
server.setProtocolNegotiationEnabled(false);
cache = AndroidShimResponseCache.create(cacheRule.getRoot(), 10 * 1024 * 1024);
urlFactory = new OkUrlFactory(new OkHttpClient());
AndroidInternal.setResponseCache(urlFactory, cache);
cookieManager = new CookieManager();
}
use of java.net.CookieManager in project okhttp by square.
the class CookiesTest method acceptOriginalServerMatchesExactly.
@Test
public void acceptOriginalServerMatchesExactly() throws Exception {
CookieManager cookieManager = new CookieManager(null, ACCEPT_ORIGINAL_SERVER);
JavaNetCookieJar cookieJar = new JavaNetCookieJar(cookieManager);
HttpUrl url = HttpUrl.parse("https://squareup.com/");
cookieJar.saveFromResponse(url, Arrays.asList(Cookie.parse(url, "a=android; Domain=squareup.com")));
List<Cookie> actualCookies = cookieJar.loadForRequest(url);
assertEquals(1, actualCookies.size());
assertEquals("a", actualCookies.get(0).name());
assertEquals("android", actualCookies.get(0).value());
}
use of java.net.CookieManager in project okhttp by square.
the class CookiesTest method testCookiesSentIgnoresCase.
@Test
public void testCookiesSentIgnoresCase() throws Exception {
client = client.newBuilder().cookieJar(new JavaNetCookieJar(new CookieManager() {
@Override
public Map<String, List<String>> get(URI uri, Map<String, List<String>> requestHeaders) throws IOException {
Map<String, List<String>> result = new LinkedHashMap<>();
result.put("COOKIE", Collections.singletonList("Bar=bar"));
result.put("cooKIE2", Collections.singletonList("Baz=baz"));
return result;
}
})).build();
MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse());
server.start();
get(server.url("/"));
RecordedRequest request = server.takeRequest();
assertEquals("Bar=bar; Baz=baz", request.getHeader("Cookie"));
assertNull(request.getHeader("Cookie2"));
assertNull(request.getHeader("Quux"));
}
Aggregations