parent
c0d1d11693
commit
b9e75fcd51
@ -1,14 +1,15 @@ |
||||
package cn.linghang.mywust.core.service.library; |
||||
|
||||
import cn.linghang.mywust.core.api.Library; |
||||
import cn.linghang.mywust.network.HttpRequest; |
||||
import cn.linghang.mywust.network.RequestFactory; |
||||
|
||||
public class LibraryAuthRequestFactory extends RequestFactory { |
||||
public static HttpRequest sessionCookieRequest() { |
||||
return DEFAULT_HTTP_REQUEST; |
||||
public static HttpRequest sessionCookieRequest(String serviceTicket) { |
||||
return makeHttpRequest(String.format(Library.LIBRARY_SESSION_COOKIE_API, serviceTicket)); |
||||
} |
||||
|
||||
public static HttpRequest indexRequest() { |
||||
return DEFAULT_HTTP_REQUEST; |
||||
return makeHttpRequest(Library.LIBRARY_INDEX_URL); |
||||
} |
||||
} |
||||
|
@ -1,9 +1,32 @@ |
||||
package cn.linghang.mywust.network; |
||||
|
||||
import java.net.URL; |
||||
|
||||
public class RequestFactory { |
||||
protected static final HttpRequest DEFAULT_HTTP_REQUEST = new HttpRequest(); |
||||
|
||||
public static HttpRequest getDefaultHttpRequest() { |
||||
return DEFAULT_HTTP_REQUEST; |
||||
public static HttpRequest makeHttpRequest(String url) { |
||||
return makeHttpRequest(url, null, null); |
||||
} |
||||
|
||||
public static HttpRequest makeHttpRequest(String url, byte[] data) { |
||||
return makeHttpRequest(url, data, null); |
||||
} |
||||
|
||||
public static HttpRequest makeHttpRequest(String url, byte[] data, String cookies) { |
||||
return HttpRequest.builder() |
||||
.url(makeUrl(url)) |
||||
.data(data) |
||||
.cookies(cookies) |
||||
.build() |
||||
.addHeaders(DEFAULT_HTTP_REQUEST.getHeaders()); |
||||
} |
||||
|
||||
public static URL makeUrl(String url) { |
||||
try { |
||||
return new URL(url); |
||||
} catch (Exception e) { |
||||
return null; |
||||
} |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue