获取自己的cookie
抽奖页面点击抽奖,找到 draw 的请求,把 cookie 全部复制下来,放到代码里就行了。
代码
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
public class Lottery {
private static final String URL = "https://api.juejin.cn/growth_api/v1/lottery/draw";
/**
* 换成自己的cookie就行了,其它代码不用动
*/
private static final String MY_COOKIES = "";
public static void main(String[] args) {
// 请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add(HttpHeaders.COOKIE, MY_COOKIES);
// 空参数 {}
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(paramMap, headers);
RestTemplate restTemplate = new RestTemplate();
for (int i = 0; i < 200; i++) {
ResponseEntity<String> stringResponseEntity = restTemplate.postForEntity(URL, httpEntity, String.class);
// 请求返回结果
System.out.println(stringResponseEntity.getBody());
}
}
}