我試圖向位於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發送的請求完全相同,不是嗎?我在這裏錯過了什麼?
感謝您的回覆!我知道'chrome:// sync',對我來說這是沒有「dev」的URL(我猜這是Chrome的非開發版本),但它不會改變任何內容。這些鏈接提供了一些見解,但不應該正確授權請求,因爲它包含'Authorization:GoogleLogin auth = ...'標頭? Chrome瀏覽器聯繫同步服務器時,該頭部保持不變,但對於我自己的請求(這只是原始副本的副本),它似乎仍然不起作用... –