Toggle navigation
首页
(current)
问答
文章
话题
商城
登录
注册
物联网卡平台各种语言api
c语言_登录 ```c CURL *hnd = curl_easy_init(); curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST"); curl_easy_setopt(hnd, CURLOPT_URL, "http://sim.openluat.com/api/auth/cus...
最近在对接合宙物联网卡系统和我自建的系统 网上的例子只有python的不太方便 提供别的例子方便下大家 c语言_登录 ```c CURL *hnd = curl_easy_init(); curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST"); curl_easy_setopt(hnd, CURLOPT_URL, "http://sim.openluat.com/api/auth/customer/login"); struct curl_slist *headers = NULL; headers = curl_slist_append(headers, "cache-control: no-cache"); headers = curl_slist_append(headers, "Content-Type: application/json"); curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\"phone\":\"用户名\",\"password\":\"密码\"}"); CURLcode ret = curl_easy_perform(hnd); ``` go_登录 ```go package main import ( "fmt" "strings" "net/http" "io/ioutil" ) func main() { url := "http://sim.openluat.com/api/auth/customer/login" payload := strings.NewReader("{\"phone\":\"用户名\",\"password\":\"密码\"}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Content-Type", "application/json") req.Header.Add("cache-control", "no-cache") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` java OK HTTP_登录 ```java OkHttpClient client = new OkHttpClient(); MediaType mediaType = MediaType.parse("application/json"); RequestBody body = RequestBody.create(mediaType, "{\"phone\":\"用户名\",\"password\":\"密码\"}"); Request request = new Request.Builder() .url("http://sim.openluat.com/api/auth/customer/login") .post(body) .addHeader("Content-Type", "application/json") .addHeader("cache-control", "no-cache") .build(); Response response = client.newCall(request).execute(); ``` nodejs_登录 ```javascript var unirest = require("unirest"); var req = unirest("POST", "http://sim.openluat.com/api/auth/customer/login"); req.headers({ "cache-control": "no-cache", "Content-Type": "application/json" }); req.type("json"); req.send({ "phone": "用户名", "password": "密码" }); req.end(function (res) { if (res.error) throw new Error(res.error); console.log(res.body); }); ``` objective-c_登录 ```objective-c #import
NSDictionary *headers = @{ @"Content-Type": @"application/json", @"cache-control": @"no-cache" }; NSDictionary *parameters = @{ @"phone": @"用户名", @"password": @"密码" }; NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://sim.openluat.com/api/auth/customer/login"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0]; [request setHTTPMethod:@"POST"]; [request setAllHTTPHeaderFields:headers]; [request setHTTPBody:postData]; NSURLSession *session = [NSURLSession sharedSession]; NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { if (error) { NSLog(@"%@", error); } else { NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; NSLog(@"%@", httpResponse); } }]; [dataTask resume]; ``` Ocaml_登录 ```objective-c open Cohttp_lwt_unix open Cohttp open Lwt let uri = Uri.of_string "http://sim.openluat.com/api/auth/customer/login" in let headers = Header.init () |> fun h -> Header.add h "Content-Type" "application/json" |> fun h -> Header.add h "cache-control" "no-cache" in let body = Cohttp_lwt_body.of_string "{\"phone\":\"用户名\",\"password\":\"密码\"}" in Client.call ~headers ~body `POST uri >>= fun (res, body_stream) -> (* Do stuff with the result *) ``` php_登录 ```php setUrl('http://sim.openluat.com/api/auth/customer/login'); $request->setMethod(HTTP_METH_POST); $request->setHeaders(array( 'cache-control' => 'no-cache', 'Content-Type' => 'application/json' )); $request->setBody('{"phone":"用户名","password":"密码"}'); try { $response = $request->send(); echo $response->getBody(); } catch (HttpException $ex) { echo $ex; } ``` ruby_登录 ```ruby require 'uri' require 'net/http' url = URI("http://sim.openluat.com/api/auth/customer/login") http = Net::HTTP.new(url.host, url.port) request = Net::HTTP::Post.new(url) request["Content-Type"] = 'application/json' request["cache-control"] = 'no-cache' request.body = "{\"phone\":\"用户名\",\"password\":\"密码\"}" response = http.request(request) puts response.read_body ``` swift_登录 ```swift import Foundation let headers = [ "Content-Type": "application/json", "cache-control": "no-cache" ] let parameters = [ "phone": "用户名", "password": "密码" ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "http://sim.openluat.com/api/auth/customer/login")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` 返回数据 ```json { "code": 0, "data": { "api_url": "/api/wechat/openapidoc", "email": "xxxxx@airm2m.com", "enable_recharge": 0, "name": "公司", "phone": "130xxxxxx", "role": 0 }, "msg": "" } ```
发表于 2019-04-12 12:17
阅读 ( 2174 )
2 推荐
收藏
你可能感兴趣的文章
相关问题
2 条评论
请先
登录
后评论
大仙
程序员
9 篇文章
作家榜
»
技术销售Delectate
43 文章
陈夏
26 文章
国梁
24 文章
miuser
21 文章
晨旭
20 文章
朱天华
19 文章
金艺
19 文章
杨奉武
18 文章
×
发送私信
发给:
内容:
×
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!