From 8e1aabc7b72c7cd99697c13ace33631636ca39a4 Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Wed, 14 Nov 2018 14:19:26 +0100 Subject: [PATCH] Use CamrecApplication's http client for cam4 unfollow requests If the cam4 http client is used, the request does not work. Must have something to do with the authentication cookies. No idea! --- src/main/java/ctbrec/sites/cam4/Cam4Model.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/ctbrec/sites/cam4/Cam4Model.java b/src/main/java/ctbrec/sites/cam4/Cam4Model.java index 17eb45d8..822b53b5 100644 --- a/src/main/java/ctbrec/sites/cam4/Cam4Model.java +++ b/src/main/java/ctbrec/sites/cam4/Cam4Model.java @@ -26,6 +26,7 @@ import ctbrec.AbstractModel; import ctbrec.Config; import ctbrec.recorder.download.StreamSource; import ctbrec.sites.Site; +import ctbrec.ui.CamrecApplication; import ctbrec.ui.HtmlParser; import okhttp3.FormBody; import okhttp3.Request; @@ -177,8 +178,14 @@ public class Cam4Model extends AbstractModel { public boolean unfollow() throws IOException { // get model user id String url = site.getBaseUrl() + '/' + getName(); - Request req = new Request.Builder().url(url).build(); - Response response = site.getHttpClient().execute(req, true); + Request req = new Request.Builder() + .url(url) + .addHeader("X-Requested-With", "XMLHttpRequest") + .build(); + + // we have to use a client without any cam4 cookies here, otherwise + // this request is redirected to the login page. no idea why + Response response = CamrecApplication.httpClient.execute(req); String broadCasterId = null; if(response.isSuccessful()) { String content = response.body().string();