2013-01-03 113 views
3

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

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未找到。 但为什么会发生这种情况? 这与Chrome发送的请求完全相同,不是吗?我在这里错过了什么?

回答

3

这里回答我的问题:问题是与编码。请求主体中的二进制数据稍微修改了一下,导致Google服务器以404错误代码进行响应(这很令人困惑)。 现在我正在使用适当的编码,一切正常。

1

如果您在Chrome的地址栏输入chrome://sync/,你将看到服务器的网址是:

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

一些你可以在这个链接找到更多的信息:

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

和/命令?需要认证。我发现一些信息可能对您有所帮助。检查这个问题的意见: http://code.google.com/p/chromium/issues/detail?id=108186

希望它有助于

+0

感谢您的回复!我知道'chrome:// sync',对我来说这是没有“dev”的URL(我猜这是Chrome的非开发版本),但它不会改变任何内容。这些链接提供了一些见解,但不应该正确授权请求,因为它包含'Authorization:GoogleLogin auth = ...'标头? Chrome浏览器联系同步服务器时,该头部保持不变,但对于我自己的请求(这只是原始副本的副本),它似乎仍然不起作用... –