我正在尝试制作 shopify 运动鞋机器人的开始部分,因此我使用 HTTP 客户端并请求向网站发送 get 请求,以便我可以访问 products/json 路径。这是以前的工作,但是,当我发送请求时,响应总是将正文返回为“”并给出响应代码 404,这意味着当网站仍然在线时找不到页面。#
这是因为我这边的事情还是什么?
谢谢
public class Cla {
public Cla(){
}
public static void main(String[] args) throws InterruptedException, IOException {
Parse(BuildConnection("https://uk.octobersveryown.com/"));
}
public static String BuildConnection(String URL) throws InterruptedException, IOException {
WebElement search ;
WebElement press;
HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(10)).build();
URL += "/products.json";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(URL + "/products.json"))
.build();
HttpResponse<String> response = null;
response = client.send(request,HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
return response.body();
}
public static String Parse(String responseBody){
String str = responseBody;
str = str.replace("{\"products\":", "");
str = str.replace("]}]}]}","]}]}]");
JSONArray arr = new JSONArray(str);
for (int i = 0; i < arr.length(); i++) {
JSONObject arrs = arr.getJSONObject(i);
String handle_str = arrs.getString("handle");
System.out.println(handle_str);
}
return null;
}