Pear :: Auth PHP 라이브러리에 대한 질문이 있습니다. 어떻게 든 "명령 줄에서 로그인"할 수 있습니까? 나는 HearpRequest로부터 Pear :: Auth를 통해 보호받는 리소스에 액세스 할 수 있다는 것을 의미한다. 나는 다른 스크립트 프로그램에서 자신을 만든다. 그리고 당신은 내게에 대한 예제 (파이썬, PHP, 자바 또는 읽을 것을)Pear :: Auth access from command line
0
A
답변
0
좋아, 희망이 다른 사람 도움이 될 수 있습니다 (작업 그것을 가지고 -.이 모든 언어로 변환하고 프로그램에서 생성 HttpRequest에 당신의 통제를 통해 :: 인증 배에 로그인 할 수 있도록 할 수 있습니다 파이썬 솔루션입니다
누군가가 자바 솔루션에 관심이 있다면import urllib
import httplib2
from urllib import urlencode
http = httplib2.Http()
url = 'LOGIN_URL'
# this applies to current version of Pear (had to add the authsecret)
body = {'username': 'USRENAME', 'password': 'PASSWORD', 'authsecret': ''}
headers = {'Content-type': 'application/x-www-form-urlencoded'}
response, content = http.request(url, 'POST', headers=headers, body=urllib.urlencode(body))
# CAREFUL!!! HERE IS THE TRICKY PART !
# response['set-cookie'] looks like this -> 'SomeSession=longID; path=/, SomeSession=longID; path=/, authchallenge=blabla; path=/'
# you need to parse it and use only authchallanage and SomeSessionpart(just one of them I think the last one) - have no idea why, but it works. So next line needs some parsing and fixing
headers = {'Cookie': response['set-cookie']} #parseme -- this is not correnct and will not work, but you have to fix it to match your implementation
print headers
# e.g. headers = {'Cookie': 'MySession=bdfdstiq90oilkpk7n4s2q2g50; authchallenge=fddtggffg5784d359c12dfad4059', 'X_REQUESTED_WITH': 'xmlhttprequest'}#the second header is optional, I needed to access some ajax call
data = dict(argument="to_pass", eg="customerID")
resp, content = http.request("secure_URL", "POST", urlencode(data), headers=headers)
print resp
print content
0
정말 달려 ...을 줄 수있는 당신은 마음에 와서이 ... 어떤 일을하려고하는 곳에서 :
을- 자격 증명을 명령 줄 인수로 전달하십시오.
- GET 요청 매개 변수의 일부로 자격 증명을 전달합니다 (아마 SSL로 가정).
- 쿠키 병이있는 cURL을 사용하십시오.
- 서비스 레이어를 구현하여 이러한 호출이 기존 배 인증과 함께 작동하는 인증을 사용하여 사용자의 필요를 용이하게하는 대체 방식으로 인증을 처리하도록합니다.
0
여기있다 :
public String getServerJson(){
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost("https://"+hostToReach+"/secure/index.php");
httpost.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("username", htmlUsername));
nvps.add(new BasicNameValuePair("password", htmlPassword));
httpost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));
try {
HttpResponse response = httpclient.execute(httpost);
HttpEntity entity = response.getEntity();
EntityUtils.consume(entity);
}
catch (Exception e){
e.printStackTrace();
}
HttpPost ajaxPost = new HttpPost("https://"+hostToReach+"/?event_id="+pmp.getPmpEventId().getEventId().toString()+"&categories_only=true&pos=true");
ajaxPost.setHeader("X_REQUESTED_WITH", "xmlhttprequest");
try {
HttpResponse catResponse = httpclient.execute(ajaxPost);
BufferedReader rd = new BufferedReader (new InputStreamReader(catResponse.getEntity().getContent()));
String line = "";
String json = "";
while ((line = rd.readLine()) != null) {
json += line;
}
EntityUtils.consume(catResponse.getEntity());
return json;
}
catch (Exception e) {
e.printStackTrace();
return "";
}
}
주 : 쿠키가 자동으로 처리된다 (당신이 그쪽에 대해 걱정할 필요가없는, 그래서 HttpClient를, 그 존재의 전체 시간을 보유하고 t)
관련 문제
- 1. Javascript REPL from command line
- 2. Jmeter-url from command line
- 3. svn history from command line
- 4. Android 빌드 .jar from command line
- 5. Python Command Line App
- 6. Truly Interactive command-line
- 7. cobertura via command line
- 8. java.lang.NoClassDefFoundError in command line
- 9. 이상한 "프로파일 링"출력. from Rails command line
- 10. PEAR :: Auth 패키지에 관한 질문
- 11. 리눅스 머신에서 PEAR Auth 문제
- 12. Java slick command line app?
- 13. Java NoClassDefFoundError in Command Line
- 14. NSTimer in command line tool
- 15. grep date from line
- 16. Facebook 연결을 PEAR Auth 클래스와 통합 하시겠습니까?
- 17. bash/command-line 기술을 향상시키는 방법은 무엇입니까?
- 18. GDB in Emacs in Command Line Arguments
- 19. .Net Application Loader 's Command Line Parser
- 20. Command Line Escape (Windows 7, CMD)
- 21. <command-line> : 오류 : makefile에
- 22. glassfish 설치 3.1.2 in command line
- 23. Open IE with command line arguement
- 24. Command-Line App C에서 파일 읽기
- 25. bash 대 scala.sys.process.Process with Command Line Arguments
- 26. Java 6/7 Decompiling Command Line
- 27. Access 2000 - Editor & Line numbers?
- 28. postgres from MS Access
- 29. BaseX Access from Java
- 30. LOAD DATA LOCAL INFILE from line after line
감사합니다 ... 나중에 다소 시간을 깨달았습니다 ... 해결책을 찾고 있습니다. 나는 반쯤 가지고있다. .. 고마워. 한 번 끝나면 여기에 올리겠습니다. – kosta5