如何在C#ASP.NET中使用API [英] How to Use API in C# ASP.NET

查看:97
本文介绍了如何在C#ASP.NET中使用API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我们有API密钥和serverURL(测试网址或sandboxURL),我们如何使用它,如何在c#中使用API​​?





sanbox url = http://beta.ipviking.com/api/ [ ^ ]



apikey = **删除* *

How to use API in c#?
if we have API Key and serverURL(test url or sandboxURL) then how we use it.

sanbox url=http://beta.ipviking.com/api/[^]

apikey=** REMOVED **

推荐答案

Hello Brijesh,



IPVIKING API文档说明以下



  • IPViking API使用REST(Representational State Transfer)设计原则,使用以下格式扩展JSON和XML。
  • API完全基于HTTP,支持方法GET,POST,PUT和DELETE
  • API基于HTTP状态代码,并将针对每个请求返回。
Hello Brijesh,

The IPVIKING API documentation states following

  • IPViking API uses REST (Representational State Transfer) design principles with the following format extension JSON and XML.
  • The API is entirely HTTP-based and support methods GET, POST, PUT and DELETE
  • API is based on HTTP Status Codes and will be returned for every request.
HttpWebRequest request = HttpWebRequest.Create("http://api.ipviking.com/api/");
request.Method = "POST";
string postData = "apiKey=** REMOVED **&method=risk&ip=10.10.1.1&";
byte[] byteArray = Encoding.UTF8.GetBytes (postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
Console.WriteLine(((HttpWebResponse)response).StatusCode);
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string strResp = reader.ReadToEnd();
Console.WriteLine (strResp);
reader.Close ();
dataStream.Close ();
response.Close ();



问候,


Regards,


这篇关于如何在C#ASP.NET中使用API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆