2012-02-08 14 views
6

मैं बाकी ग्राहक का उपयोग कर एक आरईएसटी सेवा (एचपी एएलएम 11 आरईएसटी एपीआई एफडब्ल्यूवी) के लिए अनुरोध पोस्ट करने का प्रयास कर रहा हूं और अनधिकृत प्रतिक्रिया प्राप्त कर रहा हूं। हो सकता है कि मैं दस्तावेज़ों का सही पालन नहीं कर रहा हूं लेकिन मुझे यकीन नहीं है कि मैं हेडर सही तरीके से कर रहा हूं। अब तक RestClient के लिए मेरे googling फलहीन रहा है। किसी भी मदद की सराहना की जाएगी:मैं RestClient के साथ रेल मूलभूत प्रमाणीकरण कैसे करूं?

कोड:

@alm_url  = "http://alm_url/qcbin/" 
@user_name  = "username" 
@user_password = "password" 

authentication_url = @alm_url + "rest/is-authenticate" 
resource = RestClient::Resource.new authentication_url, {:user => @user_name, :password => @user_password} 
response = resource.get 


#response = RestClient.get authentication_url, :authorization => @username, @user_password 
Rails.logger.debug response.inspect 

प्रलेखन::

ग्राहक एक वैध भेजता

@alm_url  = "http://alm_url/qcbin/" 
@user_name  = "username" 
@user_password = "password" 

authentication_url = @alm_url + "rest/is-authenticate" 
resource = RestClient::Resource.new authentication_url 
resource.head :Authorization => Base64.encode64(@user_name) + ":" + Base64.encode64(@user_password) 
response = resource.get 


#response = RestClient.get authentication_url, :authorization => @username, @user_password 
Rails.logger.debug response.inspect 

इस SO question के आधार पर मैं यह भी सफलता के बिना निम्नलिखित की कोशिश की प्रमाणीकरण बिंदु पर मूल प्रमाणीकरण शीर्षलेख।

प्राप्त/qcbin/प्रमाणीकरण सूत्री/प्रमाणित प्राधिकरण: बेसिक ABCDE123

सर्वर मूल प्रमाणीकरण हेडर सत्यापित करता है, एक नया LW-एसएसओ टोकन बनाता है और LWSSO_COOKIE_KEY के रूप में यह देता है।

authentication_url = @alm_url + "rest/is-authenticate" 

कौन सा पढ़ना चाहिए:

उत्तर

7

ठीक है ... तो पहले यह अगर मैं सही URL पर जाने में मदद करता है

authentication_url = @alm_url + "authentication-point/authenticate" 

दूसरे, यह मदद करता है अगर मैं के लिये दस्तावेज पढ़ केवल रीडेमे को देखने के बजाय RestClient। Instance Method Details के तहत उदाहरण में बहुत मदद मिली।

मेरे कोड अब लगता है कि:

@alm_url  = "http://alm_url/qcbin/" 
@user_name  = "username" 
@user_password = "password" 

authentication_url = @alm_url + "authentication-point/authenticate" 
resource = RestClient::Resource.new(authentication_url, @user_name, @user_password) 
response = resource.get 

Rails.logger.debug response.inspect 

संपादित करें:

वाह, मैं वास्तव में इस अति-सोचा। मैं साथ जा सकता था:

response = RestClient.get "http://#{@user_name}:#{@user_password}@alm_url/qcbin/authentication-point/authenticate" 
संबंधित मुद्दे