2011-03-09 6 views
1

보안 URL (https)에서 사용자 ID와 비밀번호로 데이터를 가져와야합니다. 어떻게 구현할 수 있습니까?인터넷에서 데이터 가져 오기

나는 아래의 명령을 사전에

li_rc = linet_main.GetURL("http://www.webservicex.net/WeatherForecast.asmx?WSDL", luo_data) 

감사합니다, 라 메쉬를 사용하여 일반 URL에서 데이터를 액세스 할 수있게되었습니다.

답변

4

가장 쉬운 방법은 OLE를 통해 XMLHttp 객체를 사용하는 것입니다. 다음은 암호화 된 Google 페이지를 방문하는 데 사용하는 PB 10.5의 내 보낸 함수입니다 (해당 페이지가 승인하지 않았기 때문에 게시물 부분에 404가 있지만 그 결과는 예로서 유효합니다).

$PBExportHeader$f_test_xmlhttps.srf 
global type f_test_xmlhttps from function_object 
end type 

forward prototypes 
global subroutine f_test_xmlhttps() 
end prototypes 

global subroutine f_test_xmlhttps();//First download and install the latest XMLHttp package 
//(this link goes to the one listed in the connectToNewObject call 
//http://www.microsoft.com/downloads/details.aspx?familyid=3144b72b-b4f2-46da-b4b6-c5d7485f2b42&displaylang=en#filelist 

//XMLHttp object method summary 
//http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/xmmscxmldommethods.asp 

String ls_get_url, ls_post_url 
String ls_post_variables, ls_response 
String ls_response_text, ls_status_text 
long ll_status_code 
OleObject loo_xmlhttp 

//include parameters on the URL here for get parameters 
ls_get_url = "https://encrypted.google.com/" 

try 
    //Create an instance of our COM object 
    loo_xmlhttp = CREATE oleobject 
    loo_xmlhttp.ConnectToNewObject("Msxml2.XMLHTTP.4.0") 

    //First lets do a GET request 
    //All request parameters should be included in the URL 
    loo_xmlhttp.open ("GET",ls_get_url, false) 
    loo_xmlhttp.send() 

    //Get our response 
    ls_status_text = loo_xmlhttp.StatusText 
    ll_status_code = loo_xmlhttp.Status 

    //Check HTTP Response code for errors 
    //http://kbs.cs.tu-berlin.de/~jutta/ht/responses.html 
    if ll_status_code >= 300 then 
    MessageBox("HTTP GET Request Failed", ls_response_text) 
    else 
    //Get the response we received from the web server 
    ls_response_text = loo_xmlhttp.ResponseText 

    MessageBox("GET Request Succeeded", ls_response_text) 
    end if 

    //Lets do a POST now, We would pass a String 
    //in the send() call that contains the post data in the 
    //format name1=value1&name2=value2&... 
    ls_post_url = "https://encrypted.google.com/" 
    ls_post_variables = "" 

    loo_xmlhttp.open ("POST",ls_post_url, false) 
    loo_xmlhttp.send(ls_post_variables) 

    //Get our response 
    ls_status_text = loo_xmlhttp.StatusText 
    ll_status_code = loo_xmlhttp.Status 

    //Check HTTP Response code for errors 
    //http://kbs.cs.tu-berlin.de/~jutta/ht/responses.html 
    if ll_status_code >= 300 then 
    MessageBox("HTTP POST Request Failed", ls_response_text) 
    else 
    //Get the response we received from the web server 
    ls_response_text = loo_xmlhttp.ResponseText 

    MessageBox("POST Request Succeeded", ls_response_text) 
    end if 

    //Done so cleanup 
    loo_xmlhttp.DisconnectObject() 

catch (RuntimeError rte) 

    MessageBox("Error", "RuntimeError - " + rte.getMessage()) 

end try 

end subroutine 

f_test_xmlhttps.srf로 저장하고 PowerBuilder에서 pbl로 가져옵니다. 이것은 또한 HTTP에서도 작동합니다.

+0

감사합니다. Dougman. 이것에 대해 한 가지 더 질문이 있습니다. 내 https URL에 인증 (사용자 ID/비밀번호)이 필요하면이를 어떻게 전달할 수 있습니까? 귀하의 코드에서 "ls_post_variables"가 도움이됩니까 ?? – Ramesh

+0

@Ramesh : 예, 요청에 POST를 사용하는 경우 ls_post_variables 변수에 'name1 = value1 & name2 = value2' 형식의 이름 값 쌍이 포함됩니다. 이렇게하면 웹 브라우저를 통해 POST가 수행되는 것처럼 보입니다. GET을 사용하는 경우 URL 변수 ls_get_url 끝에 'mysite.com? name1 = value1 & name2 = value2'와 같이 추가하면됩니다. –