gpt4 book ai didi

java - 检查字符串是否包含错误 404

转载 作者:行者123 更新时间:2023-11-29 05:51:59 26 4
gpt4 key购买 nike

检查字符串是否包含 error 404 的简单方法是什么?该字符串是从 HttpGet 构建的。

感谢任何帮助。

最佳答案

你最好检查一下状态码,如果状态是404,HTTP请求的结果字符串不保证包含错误码。

如果它是 Apache HTTP 客户端(它看起来像,因为你提到了 HttpGet):

get = new HttpGet("http://www.google.com");
response = client.execute(get);
if (response.getStatusLine().getStatusCode() == 404) {
System.out.println("404 - Not found!");
}

关于java - 检查字符串是否包含错误 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13552124/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com