HTTP 请求返回 html 而不是 json你好
我尝试使用以下脚本从 API 请求 JSON:
request_neu = New HTTP Request(
URL( "https://redacted.com/api/path?fileType=Json" ),
Method( "GET" ),
//headers( {"Accept: text/plain", "Accept: text/html", "Accept: */*"} ),
//headers( {"Accept: */*"} ),
//I tried everything here
Headers( {"Accept: application/json"} ),
Username( "api.user" ),
Password( "redacted" ),
Timeout( 900000 )
);
response = request_neu << send;
show(request_neu << get mime type);
show(request_neu << get status);
show(request_neu << get status message);
show(substr(response,1,999));
JSON to data table(response);我在 JSON 到数据表函数导致错误后添加了调试语句,输出为
request_neu << get mime type = "text/html; charset=utf-8";
request_neu << get status = 200;
request_neu << get status message = "HTTP/1.1 200 OK";
Substr(response, 1, 999) = "
etc
所以本质上我收到的是 html 而不是 JSON。
有趣的是,它可以与 Postman、Python 甚至 Excel 兼容。
真正有趣的是,几个月前当我创建这个脚本时它也能运行。
你知道这里发生什么事了吗?
谢谢
数据访问回复:HTTP 请求返回 html 而不是 json您是否尝试过查看 HTML 包含的内容?例如,您可以使用 Save Text File() 将其保存为 .html 页面
我很快就看不出你的语法有什么错误,下面是脚本索引中稍作修改的示例
Names Default To Here(1);
request = New HTTP Request(
url("http://httpbin.org/get"),
Method("GET"),
Headers({"Accept: application/json"}),
Username("ross"),
Password("Abc123"),
);
data = request << Send;
Show(request << get response headers, request << get last url);
回复:HTTP 请求返回 html 而不是 json当我查看 html 时,它看起来与平台的网页类似,只是相关链接已损坏。
恐怕我需要与平台的负责人讨论,因为错误似乎源于那里。
回复:HTTP 请求返回 html 而不是 json“Accept:application/json”只是向网络服务提示您想要返回的响应类型。
Web 服务可以完全自由地忽略它。
这是外部 Web 服务还是“内部”开发的服务,如果是“内部”开发的,那么您将需要与开发人员讨论在客户端请求时返回 json 数据。
如果是外部的,您能发布 api 文档吗?
回复:HTTP 请求返回 html 而不是 json一切都好吗?