gpt4 book ai didi

java - 向 Chrome 同步服务发送 HTTPS 请求 - 收到错误 404

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:19:45 29 4
gpt4 key购买 nike

我正在尝试向位于 https://clients4.google.com 的 Chrome 同步服务发送 POST 请求.我正在使用那段简短的代码来发送我之前在 BURP Suite 的帮助下捕获并保存到文件中的请求。这是 Chrome 在连接到同步服务时发送的内容。该代码打开一个 SSLSocket,连接到 Chrome 服务器并发送该文件的内容(见下文):

private void sendRequest() {
SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket socket = (SSLSocket) sslsocketfactory.createSocket("clients4.google.com", 443);
socket.startHandshake();

BufferedWriter out = new BufferedWriter(
new OutputStreamWriter(socket.getOutputStream(), "UTF8"));
BufferedReader in = new BufferedReader(
new InputStreamReader(socket.getInputStream()));

sendMessage(out, new File("request.bin"));
readResponse(in);

out.close();
in.close();
}

private void sendMessage(BufferedWriter out, File request) throws IOException {
List<String> result = getContents(request);
for (String line : result) {
out.write(line + "\r\n");
}
out.write("\r\n");
out.flush();
}

private void readResponse(BufferedReader in) throws IOException {
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
}

private List getContents(File file) throws IOException {
List<String> contents = new ArrayList<String>();
BufferedReader input = new BufferedReader(new FileReader(file));
String line;
while ((line = input.readLine()) != null) {
contents.add(line);
}
input.close();
return contents;
}

request.bin 文件如下所示(这是一个没有 SSL 的明文请求):

POST /chrome-sync/command/?client=Google+Chrome&client_id={VALID_CLIENT_ID} HTTP/1.1
Host: clients4.google.com
Connection: keep-alive
Content-Length: 1730
Authorization: GoogleLogin auth={MY_VALID_AUTH_DATA}
Content-Type: application/octet-stream
User-Agent: Chrome WIN 23.0.1271.97 (171054)
Accept-Encoding: gzip,deflate,sdch
Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

{binary data}

现在此请求失败,因为服务器返回 HTTP/1.0 404 Not Found。但是为什么会这样呢?这与 Chrome 发送的请求完全相同,不是吗?我在这里错过了什么?

最佳答案

在这里回答我自己的问题:问题出在编码上。请求正文中的二进制数据略有修改,导致 Google 服务器响应错误代码 404(这非常令人困惑)。现在我正在使用正确的编码,一切正常。

关于java - 向 Chrome 同步服务发送 HTTPS 请求 - 收到错误 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14135336/

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