原文:http://blog.csdn.net/z69183787/article/details/25372971
情境是這樣的,第三方頁面訪問需要鑒權,所以需要在HTTP頭中增加鑒權的屬性和內容發送給第三方網頁。
我試過用response.addHeader("Authorization","xxxxxxxxx")方法,但發送的請求還是不帶Authorization屬性,還請大牛們不吝指教。
你這個問題實際上是伺服器訪問第三方鑒權系統,這個訪問過程和用戶端沒關係的
和response,request都沒關係
是要在伺服器端類比http請求,在這個請求裡面增加自訂header
用HttpClient很容易
[java] view plain copy HttpClient httpClient=new HttpClient(new HttpClientParams(),new SimpleHttpConnectionManager(true)); List<Header> headers; headers=new ArrayList<Header>(); headers.add(new Header("someitem","someContent")); List<Header> headers = new ArrayList<Header>(); headers.add(new Header("Authorization", "OAuth2 " + "2.00Tw_PoBdBYEND600e0aa317Sm_qoC")); headers.add(new Header("API-RemoteIP", "http://10.1.41.252")); client.getHostConfiguration().getParams().setParameter("http.default-headers", headers); client.executeMethod(method);
這個第三方系統驗證完你的header無誤之後,肯定會在返回的session裡有些標誌
把這些標誌再給你的用戶端,這樣你的用戶端就可以訪問這個第三方了