找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 23104|回复: 0

[验证开发] API接口请求示例:C、C#、PHP、Curl、JAVA、Python、R、URL-GET等

[复制链接]
发表于 2021-2-24 17:26:43 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区

您需要 登录 才可以下载或查看,没有账号?立即注册

×
接口调用实例
用户登录(初始化)
提交地址:
[PHP] 纯文本查看 复制代码
http://demo.xinxiuvip.com/plugin.php?id=xinxiu_network:login&key=123456&action=login_user&username=demo&password=demo

提交参数
参数名
类型
必填
说明
限制
示例
key
[string]
传输密钥(后台设置)

123456
action
[string]
接口方法

login_user
username
[string]
用户名,根据$isuid值对应输入(用户名、用户ID、用户邮箱)

demo
password
[string]
密码

demo
questionid
[string]
问题id(1-7)提示问题顺序为1=母亲叫什么名字,后面2、3、4、5以此类推


answer
[string]
问题答案


isuid
[string]
用户名登录类型(1->使用用户ID登录,2->使用用户  E-mail登录;0->(默认值) 使用用户名登录)



URL-GET提交实例
用户登录(初始化)
[PHP] 纯文本查看 复制代码
##直接在网页地址栏输入即可
[url=http://demo.xinxiuvip.com/plugin.php?id=xinxiu_network:login&key=123456&action=login_user&username=demo&password=demo]http://demo.xinxiuvip.com/plugin.php?id=xinxiu_network:login&key=123456&action=login_user&username=demo&password=demo[/url]

Curl提交实例
用户登录(初始化)
[PHP] 纯文本查看 复制代码
#Curl
curl "http://demo.xinxiuvip.com/plugin.php?id=xinxiu_network:login&key=123456&action=login_user&username=demo&password=demo"

PHP提交实例
用户登录(初始化)

[PHP] 纯文本查看 复制代码
//接口请求Key,可以在后台设置
$key = "123456";
//根据接口文档设置参数信息。
$url = "http://demo.xinxiuvip.com/plugin.php?id=xinxiu_network:login";
$params = [
    "action" => "login_user",
    "key" => $key,
    "username" => "demo",
    "password" => "demo",
];
$paramstring = http_build_query($params);
$content = juheHttpRequest($url, $paramstring, 1);
$result = json_decode($content, true);
if ($result['code'] == 200) {
        exit($content);
    }elseif($result['code'] == 400){
        exit($content);
    }else{
        exit("请求失败");
}
/**
 * 请求接口返回内容
 * @param string $url [请求的URL地址]
 * @param string $params [请求的参数]
 * @param int $ipost [是否采用POST形式]
 * @return  string
 */
function juheHttpRequest($url, $params = false, $ispost = 0)
{
    $httpInfo = array();
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_USERAGENT, 'XinxiuData');
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    if ($ispost) {
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
        curl_setopt($ch, CURLOPT_URL, $url);
    } else {
        if ($params) {
            curl_setopt($ch, CURLOPT_URL, $url . '?' . $params);
        } else {
            curl_setopt($ch, CURLOPT_URL, $url);
        }
    }
    $response = curl_exec($ch);
    if ($response === FALSE) {
        //echo "cURL Error: " . curl_error($ch);
        return false;
    }
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $httpInfo = array_merge($httpInfo, curl_getinfo($ch));
    curl_close($ch);
    return $response;
}

JAVA提交实例
用户登录(初始化)
[Java] 纯文本查看 复制代码
#JAVA
import java.net.*;
import java.io.*;
public class test{
    public static void main(String args[]) throws Exception {
        URL u=new URL("http://demo.xinxiuvip.com/plugin.php?id=xinxiu_network:login&key=123456
&action=login_user&username=demo&password=demo");
        InputStream in=u.openStream();
        ByteArrayOutputStream out=new ByteArrayOutputStream();
        try {
            byte buf[]=new byte[1024];
            int read = 0;
            while ((read = in.read(buf)) > 0) {
                out.write(buf, 0, read);
            }
        }  finally {
            if (in != null) {
                in.close();
            }
        }
        byte b[]=out.toByteArray( );
        System.out.println(new String(b,"utf-8"));
    }
}

python提交实例
用户登录(初始化)
[Python] 纯文本查看 复制代码
#python
import json,urllib
from urllib import urlencode
url = 'http://demo.xinxiuvip.com/plugin.php?id=xinxiu_network:login'
params = {
  'action' : 'login_user',
  'key' : '123456',
  'username' : 'demo',
  'password' : 'demo',
}

params = urlencode(params)

f = urllib.urlopen('%s?%s' % (url, params))
api_call = f.read()
#print content
a_result = json.loads(api_call)

if a_result['code'] == '200':
  print api_call;
elseif a_result['code'] == '400':
  print api_call;
else:
  print '请求失败';

GO提交实例
用户登录(初始化)
[C] 纯文本查看 复制代码
package main

import (
        "fmt"
        "io/ioutil"
        "log"
        "net/http"
)

func main() {
        client := &http.Client{}
        req, err := http.NewRequest("GET", "http://demo.xinxiuvip.com/plugin.php?id=xinxiu_network:login&key=123456&action=login_user&username=demo5&password=demo5", nil)
        if err != nil {
                log.Fatal(err)
        }
        req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
        resp, err := client.Do(req)
        if err != nil {
                log.Fatal(err)
        }
        bodyText, err := ioutil.ReadAll(resp.Body)
        if err != nil {
                log.Fatal(err)
        }
        fmt.Printf("%s\n", bodyText)
}

Node提交实例
用户登录(初始化)
[PHP] 纯文本查看 复制代码
var request = require('request');

var headers = {
    'Content-Type': 'application/x-www-form-urlencoded'
};

var options = {
    url: 'http://demo.xinxiuvip.com/plugin.php?id=xinxiu_network:login&key=123456&action=login_user&username=demo5&password=demo5',
    headers: headers
};

function callback(error, response, body) {
    if (!error && response.statusCode == 200) {
        console.log(body);
    }
}

request(options, callback);

JavaScript提交实例
用户登录(初始化)
[PHP] 纯文本查看 复制代码
var myHeaders = new Headers();
myHeaders.append("User-Agent", "Apifox/1.0.0 ([url=http://www.xinxiuvip.com/]http://www.xinxiuvip.com/[/url])");
myHeaders.append("Accept", "*/*");
myHeaders.append("Host", "demo35.xinxiuvip.com");
myHeaders.append("Connection", "keep-alive");
myHeaders.append("Cookie", "MIYB_2132_saltkey=eRSG43Kb; MIYB_2132_lastvisit=1706621745; MIYB_2132_sid=fl3PuU; MIYB_2132_lastact=1706625345%09plugin.php%09; MIYB_2132_microtime=1706625345.6864");

var requestOptions = {
   method: 'GET',
   headers: myHeaders,
   redirect: 'follow'
};

fetch("http://demo35.xinxiuvip.com/plugin.php?id=xinxiuvip_network:login&key=123456&action=login_user&username=demo&password=demo", requestOptions)
   .then(response => response.text())
   .then(result => console.log(result))
   .catch(error => console.log('error', error));

Swift提交实例
用户登录(初始化)
[PHP] 纯文本查看 复制代码
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

var semaphore = DispatchSemaphore (value: 0)

var request = URLRequest(url: URL(string: "http://demo35.xinxiuvip.com/plugin.php?id=xinxiuvip_network:login&key=123456&action=login_user&username=demo&password=demo")!,timeoutInterval: Double.infinity)
request.addValue("Apifox/1.0.0 ([url=http://www.xinxiuvip.com/]http://www.xinxiuvip.com/[/url])", forHTTPHeaderField: "User-Agent")
request.addValue("*/*", forHTTPHeaderField: "Accept")
request.addValue("demo35.xinxiuvip.com", forHTTPHeaderField: "Host")
request.addValue("keep-alive", forHTTPHeaderField: "Connection")
request.addValue("MIYB_2132_saltkey=eRSG43Kb; MIYB_2132_lastvisit=1706621745; MIYB_2132_sid=fl3PuU; MIYB_2132_lastact=1706625345%09plugin.php%09; MIYB_2132_microtime=1706625345.6864", forHTTPHeaderField: "Cookie")

request.httpMethod = "GET"

let task = URLSession.shared.dataTask(with: request) { data, response, error in 
   guard let data = data else {
      print(String(describing: error))
      semaphore.signal()
      return
   }
   print(String(data: data, encoding: .utf8)!)
   semaphore.signal()
}

task.resume()
semaphore.wait()

C提交实例
用户登录(初始化)
[PHP] 纯文本查看 复制代码
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
   curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
   curl_easy_setopt(curl, CURLOPT_URL, "http://demo35.xinxiuvip.com/plugin.php?id=xinxiuvip_network:login&key=123456&action=login_user&username=demo&password=demo");
   curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
   curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
   struct curl_slist *headers = NULL;
   headers = curl_slist_append(headers, "User-Agent: Apifox/1.0.0 ([url=http://www.xinxiuvip.com/]http://www.xinxiuvip.com/[/url])");
   headers = curl_slist_append(headers, "Accept: */*");
   headers = curl_slist_append(headers, "Host: demo35.xinxiuvip.com");
   headers = curl_slist_append(headers, "Connection: keep-alive");
   headers = curl_slist_append(headers, "Cookie: MIYB_2132_saltkey=eRSG43Kb; MIYB_2132_lastvisit=1706621745; MIYB_2132_sid=fl3PuU; MIYB_2132_lastact=1706625345%09plugin.php%09; MIYB_2132_microtime=1706625345.6864");
   curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
   res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);

C#提交实例
用户登录(初始化)
[PHP] 纯文本查看 复制代码
var client = new RestClient("http://demo35.xinxiuvip.com/plugin.php?id=xinxiuvip_network:login&key=123456&action=login_user&username=demo&password=demo");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
client.UserAgent = "Apifox/1.0.0 ([url=http://www.xinxiuvip.com/]http://www.xinxiuvip.com/[/url])";
request.AddHeader("Accept", "*/*");
request.AddHeader("Host", "demo35.xinxiuvip.com");
request.AddHeader("Connection", "keep-alive");
request.AddHeader("Cookie", "MIYB_2132_saltkey=eRSG43Kb; MIYB_2132_lastvisit=1706621745; MIYB_2132_sid=fl3PuU; MIYB_2132_lastact=1706625345%09plugin.php%09; MIYB_2132_microtime=1706625345.6864");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

Ruby提交实例
用户登录(初始化)
[PHP] 纯文本查看 复制代码
require "uri"
require "net/http"

url = URI("http://demo35.xinxiuvip.com/plugin.php?id=xinxiuvip_network:login&key=123456&action=login_user&username=demo&password=demo")

http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Get.new(url)
request["User-Agent"] = "Apifox/1.0.0 ([url=http://www.xinxiuvip.com/]http://www.xinxiuvip.com/[/url])"
request["Accept"] = "*/*"
request["Host"] = "demo35.xinxiuvip.com"
request["Connection"] = "keep-alive"
request["Cookie"] = "MIYB_2132_saltkey=eRSG43Kb; MIYB_2132_lastvisit=1706621745; MIYB_2132_sid=fl3PuU; MIYB_2132_lastact=1706625345%09plugin.php%09; MIYB_2132_microtime=1706625345.6864"

response = http.request(request)
puts response.read_body

OCaml提交实例
用户登录(初始化)
[PHP] 纯文本查看 复制代码
open Lwt
open Cohttp
open Cohttp_lwt_unix

let reqBody = 
   let uri = Uri.of_string "http://demo35.xinxiuvip.com/plugin.php?id=xinxiuvip_network:login&key=123456&action=login_user&username=demo&password=demo" in
   let headers = Header.init ()
      |> fun h -> Header.add h "User-Agent" "Apifox/1.0.0 ([url=http://www.xinxiuvip.com/]http://www.xinxiuvip.com/[/url])"
      |> fun h -> Header.add h "Accept" "*/*"
      |> fun h -> Header.add h "Host" "demo35.xinxiuvip.com"
      |> fun h -> Header.add h "Connection" "keep-alive"
      |> fun h -> Header.add h "Cookie" "MIYB_2132_saltkey=eRSG43Kb; MIYB_2132_lastvisit=1706621745; MIYB_2132_sid=fl3PuU; MIYB_2132_lastact=1706625345%09plugin.php%09; MIYB_2132_microtime=1706625345.6864"
   in
   Client.call ~headers `GET uri >>= fun (_resp, body) ->
   body |> Cohttp_lwt.Body.to_string >|= fun body -> body

let () =
   let respBody = Lwt_main.run reqBody in
   print_endline (respBody)

Dart提交实例
用户登录(初始化)
[PHP] 纯文本查看 复制代码
var headers = {
   'User-Agent': 'Apifox/1.0.0 ([url=http://www.xinxiuvip.com/]http://www.xinxiuvip.com/[/url])',
   'Accept': '*/*',
   'Host': 'demo35.xinxiuvip.com',
   'Connection': 'keep-alive',
   'Cookie': 'MIYB_2132_saltkey=eRSG43Kb; MIYB_2132_lastvisit=1706621745; MIYB_2132_sid=fl3PuU; MIYB_2132_lastact=1706625345%09plugin.php%09; MIYB_2132_microtime=1706625345.6864'
};
var request = http.Request('GET', Uri.parse('http://demo35.xinxiuvip.com/plugin.php?id=xinxiuvip_network:login&key=123456&action=login_user&username=demo&password=demo'));

request.headers.addAll(headers);

http.StreamedResponse response = await request.send();

if (response.statusCode == 200) {
   print(await response.stream.bytesToString());
}
else {
   print(response.reasonPhrase);
}

R 提交实例
用户登录(初始化)
[PHP] 纯文本查看 复制代码
library(httr)

headers = c(
   'User-Agent' = 'Apifox/1.0.0 ([url=http://www.xinxiuvip.com/]http://www.xinxiuvip.com/[/url])',
   'Accept' = '*/*',
   'Host' = 'demo35.xinxiuvip.com',
   'Connection' = 'keep-alive',
   'Cookie' = 'MIYB_2132_saltkey=eRSG43Kb; MIYB_2132_lastvisit=1706621745; MIYB_2132_sid=fl3PuU; MIYB_2132_lastact=1706625345%09plugin.php%09; MIYB_2132_microtime=1706625345.6864'
)

res <- VERB("GET", url = "http://demo35.xinxiuvip.com/plugin.php?id=xinxiuvip_network:login&key=123456&action=login_user&username=demo&password=demo", add_headers(headers))

cat(content(res, 'text'))
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|新秀网络验证系统API[软著登字第13061951号] ( 豫ICP备2021033257号-1 )

GMT+8, 2024-11-13 14:36 , Processed in 0.232699 second(s), 44 queries , Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表