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

问题描述

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





sanbox url = []



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 **

推荐答案

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 16:46