7
我有些工作的Java代碼,執行以下操作:HttpURLConnection的addRequestProperty方法不傳遞參數
URL myUrl = new URL("http://localhost:8080/webservice?user=" + username + "&password=" + password + "&request=x");
HttpURLConnection myConnection = (HttpURLConnection) myUrl.openConnection();
myConnection.setRequestMethod("POST");
// code continues to read the response stream
然而,我注意到,我的web服務器的訪問日誌包含所有誰連接用戶的明文密碼。我想從訪問日誌中獲得此信息,但Web服務器管理員聲稱這需要在我的代碼中進行更改,而不是通過Web服務器配置進行更改。
我試過的代碼更改爲以下:
URL myUrl = new URL("http://localhost:8080/webservice");
HttpURLConnection myConnection = (HttpURLConnection) myUrl.openConnection();
myConnection.setRequestMethod("POST");
// start of new code
myConnection.setDoOutput(true);
myConnection.addRequestProperty("username", username);
myConnection.addRequestProperty("password", password);
myConnection.addRequestProperty("request", "x");
// code continues to read the response stream
現在的訪問日誌不包含用戶名/密碼/請求方法。但是,webservice現在會拋出一個異常,指示它沒有收到任何用戶名/密碼。
我在客戶端代碼中做了什麼錯誤?我也嘗試使用「setRequestProperty」而不是「addRequestProperty」,它具有相同的破壞行爲。
你應該驗證你的答案;-) – JonesV 2014-05-08 09:43:10
瓊斯和大衛,你可以告訴我,我可以發送圖片爲u發送用戶名和密碼?看到我的問題在這裏http://stackoverflow.com/questions/27615276/how-to-send-data-to-server – 2014-12-23 07:27:13
所有帖子在這裏我已經搜索,幾乎完全相同,你的解決我的問題,謝謝你大衛! – Rob85 2016-05-18 21:36:53