JAVA HTTPclient頭中增加自訂的屬性__JAVA

來源:互聯網
上載者:User

原文: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裡有些標誌

把這些標誌再給你的用戶端,這樣你的用戶端就可以訪問這個第三方了

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.