• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

使用C#访问rest api

用户头像
it1352
帮助1

问题说明

我有这样的休息api url

https://example.com/ProductAPI/api/V1/getproduct

这个api有api_key,用户名和密码。如何使用c#访问此api和getproduct详细信息。

将从另一个URL获取的令牌

https:// example。 com / ProductAPI /通过用户名,密码,client_key和generictype



我尝试过:



WebRequest request = WebRequest.Create(@https://example.com/ProductAPI/api/V1/getproduct);



request.Method =GET;

request.Headers.Add(api_key,5g13441f-6915-4a34-8a53-bcb4er88b554);

request.Headers [授权] =基本 Convert.ToBase64String(Encoding.Default.GetBytes(admin:123));

request.ContentLength = 0;

request.ContentType = @application / json; charset = utf-8;

HttpWebResponse响应=(HttpWebResponse)request.GetResponse();

string jsonResponse = string.Empty;

using(StreamReader sr = new StreamReader(response.GetResponseStream()))

{

jsonResponse = sr.ReadToEnd();

Console.WriteLine(jsonResponse);

Console.ReadLine( );

}

I have rest api url like this
https://example.com/ProductAPI/api/V1/getproduct.
This api has api_key,username and password.How can I access this api and getproduct details using c#.
The token which will get from another url
https://example.com/ProductAPI/ by passing username,password,client_key and generictype

What I have tried:

WebRequest request = WebRequest.Create(@"https://example.com/ProductAPI/api/V1/getproduct");

request.Method = "GET";
request.Headers.Add("api_key","5g13441f-6915-4a34-8a53-bcb4er88b554");
request.Headers["Authorization"] = "Basic" Convert.ToBase64String(Encoding.Default.GetBytes("admin:123"));
request.ContentLength = 0;
request.ContentType = @"application/json; charset=utf-8";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string jsonResponse = string.Empty;
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
jsonResponse = sr.ReadToEnd();
Console.WriteLine(jsonResponse);
Console.ReadLine();
}

正确答案

#1
请参阅以下链接

link1

link2



我希望它适合你。
Refer following link
link1
link2

I hope it will work for you.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcffcfa
系列文章
更多 icon
同类精品
更多 icon
继续加载