http協議:
http://api.youripapi.com/ip/
https協議:
https://api.youripapi.com/ip/
* API接口可能會因為各種網絡原因和攻擊都可能産生阻斷,請開發時做好冗餘和異常處理
* 當HTTP請求返回的狀態碼非200時,請做異常處理,比如 202 狀態碼造成的原因可能是無效Token、餘額不足、格式錯誤
C#(.net)web調用iP查詢接口示例:
using System;
using System.Collections.Generic;
using System.Web;
using System.Net;
using System.Text;
public class youripapi
{
public static string GetIPData(string token, string ip = null, string datatype = "txt")
{
if (string.IsNullOrEmpty(ip))
{
ip = HttpContext.Current.Request.UserHostAddress;
}
string url = string.Format("https://api.youripapi.com/ip/?ip={0}&datatype={1}&token={2}", ip, datatype, token);
using (WebClient client = new WebClient())
{
client.Encoding = Encoding.UTF8;
return client.DownloadString(url);
}
}
}
string data = youripapi.GetIPData("00d5cb1fac5dc5cbfe2ff218222a2dfd33", Request.UserHostAddress);
Console.WriteLine(data);
Response.Write(data);
<%
string ip = Request.UserHostAddress;
string strMid = "777"; //用戶中心查看您的mid
string oid = "777"; //用戶中心查看您的oid
string token = "00d5cb1fac5dc5cbfe2ff218222a2dfd33"; //用戶中心查看您的token
string url = "https://api.youripapi.com/ip/?";
string str = "ip=" + ip + "&token=" + token;
string sign = FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower();
%>
<script type="text/javascript">
function find(str){alert(str.data);}
</script>
<script type="text/javascript" src="<%= url+"ip="+ip+"&callback=find&mid="+strMid+"&oid="+oid+"&sign="+sign %>"></script>