我創建的應用程序在GAE上運行並連接到特定頁面,自動登錄到此頁面並在登錄後我想接收html並處理它。在建立java.net連接時在GAE上獲取IOException
這裏是有問題的(writer.write部分和connection.connect())的部分代碼:
this.username = URLEncoder.encode(username, "UTF-8");
this.password = URLEncoder.encode(password, "UTF-8");
this.login = "login";
connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
OutputStreamWriter writer = new OutputStreamWriter(
connection.getOutputStream());
writer.write("str_login=" + login + "&str_user=" + username
+ "&str_pass=" + password);
writer.close();
connection.connect();
我收到IOException異常(connection.connect()),而establishig連接。問題是「application/x-www-form-urlencoded」數據。當我將錯誤的參數傳遞給頁面(例如str_pasSSs,str_usernaAAme或根本沒有參數)時,我無法登錄,但我確實得到了登錄頁面的html響應。所以,Google App Engine似乎不支持這種通信。是否有可能以GAE支持的其他方式登錄到此頁面?
在Wireshark中,我看到用戶名和密碼是以明文形式作爲基於行的文本數據(application/x-www-form-urlencoded)發送的。我知道這是不安全的,但它是這樣的。
您是否嘗試設置內容類型? –
是的,我試過但沒有幫助。事情是,當我在本地運行應用程序(本地主機)時根本沒有問題。實際上,我看到connection.connect()在Google App Engine上引發IOException。 – user1940909