Consume oData service from Delphi

南笙酒味 提交于 2019-12-22 04:11:03

问题


How can I consume a oData webservice from Delphi (I'm trying to interact with the new Bing Search Azure API)? There is almost no information to do this in Delphi. There is a post here but it does not help much explaining how to consume such service from a Delphi point of view. Can anyone provide a simple example?


回答1:


Here is a very simple example of consuming an oData service in Delphi XE using the netflix oData service:

program oDataDemo;

{$APPTYPE CONSOLE}

uses
  SysUtils, msxml, Variants, Activex;

var
  httpRequest: IXMLHttpRequest;
  oDataServiceURI: String;
  oDataFilter: String;
  xmlResults: String;
begin
  try
    oDataServiceURI := 'http://odata.netflix.com/v2/Catalog/Titles()';
    oDataFilter := '?$top=10';
    coinitialize(nil);
    httpRequest := CoXMLHTTP.Create;
    httpRequest.open('GET', UTF8Encode(oDataServiceURI + oDataFilter), false, EmptyParam, EmptyParam);
    httpRequest.send(EmptyParam);
    xmlResults := httpRequest.responseText;
    WriteLn(xmlResults);

  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


来源:https://stackoverflow.com/questions/11721549/consume-odata-service-from-delphi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!