简体   繁体   English

如何在MVC应用程序中不使用sodaclient的情况下与OpenData API端点通信

[英]How to talk to OpenData API Endpoint without using sodaclient in mvc application

How can I talk to an OpenData API Endpoint (private dataset) in an MVC application without using sodaclient? 如何在不使用sodaclient的情况下与MVC应用程序中的OpenData API端点(私有数据集)进行通信? I have an apptoken and credentials. 我有一个apptoken和凭据。

Just to clarify, it's a private dataset, correct? 为了澄清起见,这是一个私有数据集,对吗?

You'll need to make a RESTful HTTP call from your ASP.NET code, and include your application token as the X-App-Token header and provide HTTP Basic authentication with your user credentials. 您需要从ASP.NET代码进行RESTful HTTP调用,并将您的应用程序令牌包含为X-App-Token标头,并使用您的用户凭据提供HTTP Basic身份验证。

Here's some helpful documentation: 以下是一些有用的文档:

SoQL is pretty straightforward, so you'll just need to construct the right SoQL query for your dataset and pass that in your GetAsync call. SoQL非常简单明了,因此您只需要为数据集构造正确的SoQL查询并将其传递到GetAsync调用中即可。 I am not a ASP.NET programmer, but I think it'd look something like this. 我不是ASP.NET程序员,但我认为它看起来像这样。

using (var client = new HttpClient())
{
    client.BaseAddress = new Uri("https://data.government.gov/");
    client.DefaultRequestHeaders.Accept.Clear();
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    // Also add X-App-Token and authentication headers here

    // New code:
    HttpResponseMessage response = await client.GetAsync("resource/644b-gaut.json?$where=date > '2014-12-01'");
    if (response.IsSuccessStatusCode)
    {
        // Do stuff
    }
}

Adding in the authentication and X-App-Token headers are left as an exercise to the reader. 身份验证和X-App-Token标头的添加留给读者练习。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 API 与应用程序与 MVC 4 一起使用 - Using API with Application with MVC 4 从同一MVC应用程序调用Web api端点超时 - call to web api endpoint from same mvc application is timing out 如何在不使用Azure的情况下在MVC应用程序中显示Power BI仪表板 - How to show Power BI dashboard in MVC application without using Azure 如何让Asp.net MVC控制器与Google Maps API通讯-动态添加标记 - How to get asp.net mvc controller to talk with google maps api - Adding markers dynamically 不使用实体框架的MVC应用程序架构 - Architecture of MVC application without using entity framework 使用 Web API 在 MVC 应用程序中插入记录 - Inserting records in MVC Application using web API 如何在混合Web API和MVC应用程序中使用Autofac解析Web API控制器? - How do I resolve Web API controllers using Autofac in a mixed Web API and MVC application? 使用 Web Api 为 MVC 应用程序创建面向服务的应用程序的方法 - Approach to create service oriented application for MVC application using Web Api ASP MVC Web API端点返回404 - ASP MVC Web API endpoint returning 404 如何在不丢失会话的情况下更新asp net webforms或mvc应用程序? - How to update asp net webforms or mvc application without losing session?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM