【问题标题】:Sending HTTPS request to Chrome sync service - getting error 404向 Chrome 同步服务发送 HTTPS 请求 - 收到错误 404
【发布时间】:2013-01-03 08:28:53
【问题描述】:

我正在尝试向位于 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 发送的请求完全相同,不是吗?我在这里想念什么?

【问题讨论】:

    标签: java sockets ssl


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      如果您在 chrome 的地址栏中输入 chrome://sync/,您将看到服务器 url 为:

      https://clients4.google.com/chrome-sync/dev
      

      您可以在此链接中找到更多信息:

      http://code.google.com/p/chromium/issues/detail?id=90811

      还有/命令?需要认证。我发现一些信息可能对你有帮助。检查此问题的 cmets: http://code.google.com/p/chromium/issues/detail?id=108186

      希望对你有帮助

      【讨论】:

      • 感谢您的回复!我知道chrome://sync,对我来说它是没有“dev”的 URL(我猜它是 Chrome 的非开发者版本),但它并没有改变任何东西。这些链接提供了一些见解,但不应该正确授权请求,因为它包含Authorization: GoogleLogin auth=... 标头吗?每当 Chrome 联系同步服务器时,该标头都保持不变,但对于我自己的请求(这只是原始请求的副本),它似乎仍然不起作用……
      猜你喜欢
      • 1970-01-01
      • 2018-10-04
      • 2012-12-12
      • 2012-10-18
      • 1970-01-01
      • 2016-04-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多