Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Branch.io API在C中的实现#_C#_Api_Branch.io - Fatal编程技术网

C# Branch.io API在C中的实现#

C# Branch.io API在C中的实现#,c#,api,branch.io,C#,Api,Branch.io,我想在我的应用程序中实现Branch.io API。服务器端是.Net,我在C#中找不到任何API实现的解决方案。在Branch.io中,用于使用API的每个文档都提到由邮递员提供响应,而不使用C# 有什么方法或者它只是在客户端实现吗?它不是最好看的代码,但适合您的任务: public class Rootobject { public string branch_key { get; set; } public string channel { get; set; }

我想在我的应用程序中实现Branch.io API。服务器端是.Net,我在C#中找不到任何API实现的解决方案。在Branch.io中,用于使用API的每个文档都提到由邮递员提供响应,而不使用C#


有什么方法或者它只是在客户端实现吗?

它不是最好看的代码,但适合您的任务:

public class Rootobject
{
    public string branch_key { get; set; }
    public string channel { get; set; }
    public string feature { get; set; }
    public string campaign { get; set; }
    public string stage { get; set; }
    public string[] tags { get; set; }
    public Data data { get; set; }
}

public class Data
{
    public string canonical_identifier { get; set; }
    public string og_title { get; set; }
    public string og_description { get; set; }
    public string og_image_url { get; set; }
    public string desktop_url { get; set; }
    public bool custom_boolean { get; set; }
    public int custom_integer { get; set; }
    public string custom_string { get; set; }
    public int[] custom_array { get; set; }
    public Custom_Object custom_object { get; set; }
}

public class Custom_Object
{
    public string random { get; set; }
}
以上这些类是要发送的数据。请求方法应如下所示:

public async Task GetUrlData(string url, string branchKey)
        {
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri("https://api.branch.io");
            client.DefaultRequestHeaders
                .Accept
                .Add(new MediaTypeWithQualityHeaderValue("application/json"));
            string requestUrl = $"/v1/url?url{url}&key={branchKey}";

            var payload = new Rootobject();

            var stringPayload = JsonConvert.SerializeObject(payload);
            var httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json");
            var response = await client.PostAsync(requestUrl, httpContent);

            if (response.Content != null)
            {
                var responseContent = await response.Content.ReadAsStringAsync();
            }
        }

responseContent变量是您要查找的api的响应。`

请尽量解释得更清楚些。你是怎么做到的?出了什么问题?@OzanTopal谢谢,我真的想知道如何在C#中使用branch.io API,在我的页面中,我有一个可以共享的项目列表,我应该使用branch.io API来生成这些链接。我阅读了这份文件:但我不理解申请项目,也不清楚。我需要将链接创建响应作为我提到的列表中每个项目的共享URL发送给客户端。您以前使用过.net framework中的HttpClient类吗?您可以在此客户端的帮助下发出http请求。@OzanTopal我的评论已更新,关于您的问题,我以前从未使用过它