从互联网获取数据

发布于 2024-10-21 13:52:31 字数 218 浏览 0 评论 0原文

我需要使用用户 ID 和密码从安全 URL (https) 获取数据。我怎样才能实现它。

我可以使用以下命令从普通 URL 访问数据

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

提前致谢, 拉梅什。

I need to get the data from a secure URL (https) with a userid and password. How can I implement that.

I am able to access the data from a normal URL using the below command

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

Thanks in advance,
Ramesh.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘年祭陌 2024-10-28 13:52:31

我发现最简单的方法是通过 OLE 使用 XMLHttp 对象。这是 PB 10.5 的导出函数,它使用它来访问加密的 Google 页面(由于其页面不接受它们,因此在帖子部分出现 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。

The approach I've found easiest is using the XMLHttp object via OLE. Here is an exported function from PB 10.5 that uses it to hit the encrypted Google page (it 404's on the post portion since their page is not accepting them, but the result is valid as an example).

$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

Save that off as f_test_xmlhttps.srf and import into a pbl in PowerBuilder. This also works for HTTP as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文