【问题标题】:TIdHttp returns JSON, TWebBrowser returns xml from Tableau server requestTIdHttp 返回 JSON,TWebBrowser 从 Tableau 服务器请求返回 xml
【发布时间】:2018-06-29 19:53:06
【问题描述】:

面对 Delphi/Indy/TWebBrowser/Tableau 传奇中的更多奇特挑战。

我很难理解为什么使用 TIdHttp 组件向 Tableau 服务器发送 GET 请求总是返回 JSON 响应,而具有相同身份验证标头的 TWebBrowser 控件中的相同请求返回 XML 响应。

我稍微更喜欢 XML——尽管它更占用带宽——因为我们有很多 XML 基础设施,而目前没有 JSON 基础设施。

当我使用 TIdHttp 组件发送请求时,我将使用以下参数发送它:

  http.Request.CustomHeaders.Text := GetAuthHeader(FToken);
  http.Request.ContentType := 'application/json';

我也试过这个:

  http.Request.ContentType := 'text/xml';
  http.Request.Accept := 'text/xml';

  http.Request.ContentType := 'application/xml';
  http.Request.Accept := application/xml';

  <no settings specified for accept and contenttype, just let it use the defaults>

...

  sHTML := http.Get('http://<myserver>/api/3.0/sites/' + FSiteId + '/views')

...并始终以 JSON 格式接收响应。

当我使用 TWebBrowser 发送相同的请求时:

var
  hdr,flags,targetframe,postdata,Aurl: OleVariant;
begin
  AUrl := http://<myserver>/api/3.0/sites/' + FSiteId + '/views';
  flags := navNoHistory+navNoReadFromCache+navNoWriteToCache;
  targetframe := 1;
  postdata := 1;
  hdr := GetAuthHeader(FToken);
  Navigate2(Aurl,flags,targetframe,postdata,hdr);
end;

...响应总是以 XML 形式返回。

有谁明白为什么会发生这种情况?我尝试记录原始请求以查看 TWebBrowser 是如何设置它的,但似乎无法获取原始请求。或许我应该设置一个代理服务器...

TIA

【问题讨论】:

    标签: json delphi indy twebbrowser tableau-api


    【解决方案1】:

    解决了 - 有一个

    http.Request.ContentType := 'application/json...';
    

    还有一个

    http.Request.Accept := 'application/json...';
    

    仍然在表单创建事件中徘徊。

    【讨论】:

      猜你喜欢
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-22
      • 1970-01-01
      • 1970-01-01
      • 2012-04-05
      • 1970-01-01
      相关资源
      最近更新 更多