




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、工程安全類,解決項目中經常遇到. 關于AppDelegate里面的那些函數方法 關于hidesBottomBarWhenPushed 隱藏tabor. 關于IQKeyboardManager 鍵盤第三方庫 /創(chuàng)建套接字 SOCKET servSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); /綁定套接字 sockaddr_in sockAddr; memset(&sockAddr, 0, sizeof(sockAddr); /每個字節(jié)都用0填充 sockAddr.sin_family = PF_INET; /使用IPv4地址 /sock
2、Addr.sin_addr.s_addr = htonl(INADDR_ANY); /自動獲取IP地址 sockAddr.sin_addr.s_addr = inet_addr("54"); sockAddr.sin_port = htons(4321); /端口 bind(servSock, (SOCKADDR*)&sockAddr, sizeof(SOCKADDR); /對于一些篩選之類的功能使用NSSet or NSMutableS. /進入監(jiān)聽狀態(tài) listen(servSock, 20); /接收客戶端請求 SOCKADDR cl
3、ntAddr; int nSize = sizeof(SOCKADDR); SOCKET clntSock; char RecvBufferMAXBYTE; COORD old_postion = 0, 0; while (1) clntSock = accept(servSock, (SOCKADDR*)&clntAddr, &nSize); memset(RecvBuffer, 0, MAXBYTE); do recv(clntSock, RecvBuffer, MAXBYTE, NULL); while (0 = strlen(RecvBuffer); old_posti
4、on = get_xy(); if (g_postion < 20) gotoxy(0, g_postion+); else g_postion = 1; gotoxy(0, g_postion); +g_postion; ClearScreen(); /system("cls"); printf_s("You: %sn", RecvBuffer); gotoxy(old_postion.X, old_postion.Y); /關閉套接字 closesocket(clntSock); closesocket(servSock); /終止 DLL 的
5、使用 WSACleanup(); system("pause"); return 0; 代碼 Google Go代碼 package mainimport ( "io/ioutil" "net/http" "net/" "fmt" "encoding/json") /-/ 黃金數據調用示例代碼 聚合數據/ 在線接口文檔:www/docs/29/- const APPKEY = "*" /您申請的APPKEY func main() /1.上海黃金交易所 R
6、equest1() /2.上海期貨交易所 Request2() /3.銀行賬戶黃金 Request3() /1.上海黃金交易所func Request1() /請求地址 juhe :="web:8080/finance/gold/shgold" /初始化參數 param:=.Values /配置請求參數,方法內部已處理encode問題,中文參數可以直接傳參 param.Set("key",APPKEY) /APP Key param.Set("v","") /JSON格式版本(0或1)默認為0 /發(fā)送請求 data
7、,err:=Get(juhe,param) if err!=nil fmt.Errorf("請求失敗,錯誤信息:rn%v",err) else var netReturn mapstringinterface json.Unmarshal(data,&netReturn) if netReturn"error_code".(float64)=0 fmt.Printf("接口返回result字段是:rn%v",netReturn"result") /2.上海期貨交易所func Request2() /請求地址
8、 juhe :="web:8080/finance/gold/shfuture" /初始化參數 param:=.Values /配置請求參數,方法內部已處理encode問題,中文參數可以直接傳參 param.Set("key",APPKEY) /APP Key param.Set("v","") /JSON格式版本(0或1)默認為0 /發(fā)送請求 data,err:=Get(juhe,param) if err!=nil fmt.Errorf("請求失敗,錯誤信息:rn%v",err) else
9、var netReturn mapstringinterface json.Unmarshal(data,&netReturn) if netReturn"error_code".(float64)=0 fmt.Printf("接口返回result字段是:rn%v",netReturn"result") /3.銀行賬戶黃金func Request3() /請求地址 juhe :="web:8080/finance/gold/bankgold" /初始化參數 param:=.Values /配置請求參數,方法
10、內部已處理encode問題,中文參數可以直接傳參 param.Set("key",APPKEY) /APP Key /發(fā)送請求 data,err:=Get(juhe,param) if err!=nil fmt.Errorf("請求失敗,錯誤信息:rn%v",err) else var netReturn mapstringinterface json.Unmarshal(data,&netReturn) if netReturn"error_code".(float64)=0 fmt.Printf("接口返回res
11、ult字段是:rn%v",netReturn"result") / get 網絡請求func Get(api string,params .Values)(rsbyte ,err error) var *. ,err=.Parse(api) if err!=nil fmt.Printf("解析錯誤:rn%v",err) return nil,err /如果參數中有中文參數,這個方法會進行Encode .RawQuery=params.Encode() resp,err:=http.Get(.String() if err!=nil fmt.Pr
12、intln("err:",err) return nil,err defer resp.Body.Close() return ioutil.ReadAll(resp.Body) / post 網絡請求 ,params 是.Values類型func Post(api string, params .Values)(rsbyte,err error) resp,err:=http.PostForm(api, params) if err!=nil return nil ,err defer resp.Body.Close() return ioutil.ReadAll(res
13、p.Body)代碼描述:基于GO的黃金數據接口調用代碼實例關聯(lián)數據:黃金數據代碼 C#代碼 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Net;using System.IO;using Xfrog.Net;using System.Diagnostics;using System.Web; /-/ 黃金數據調用示例代碼 聚合數據/ 在線接口文檔:www/docs/29/ 代碼中JsonObject類下載地址:/- namespace Console
14、API class Program static void Main(string args) string appkey = "*" /配置您申請的appkey /1.上海黃金交易所 string 1 = "web:8080/finance/gold/shgold" var parameters1 = new Dictionary<string, string>(); parameters1.Add("key", appkey);/你申請的key parameters1.Add("v" , "
15、;"); /JSON格式版本(0或1)默認為0 string result1 = sendPost(1, parameters1, "get"); JsonObject newObj1 = new JsonObject(result1); String errorCode1 = newObj1"error_code".Value; if (errorCode1 = "0") Debug.WriteLine("成功"); Debug.WriteLine(newObj1); else /Debug.Write
16、Line("失敗"); Debug.WriteLine(newObj1"error_code".Value+":"+newObj1"reason".Value); /2.上海期貨交易所 string 2 = "web:8080/finance/gold/shfuture" var parameters2 = new Dictionary<string, string>(); parameters2.Add("key", appkey);/你申請的key param
17、eters2.Add("v" , ""); /JSON格式版本(0或1)默認為0 string result2 = sendPost(2, parameters2, "get"); JsonObject newObj2 = new JsonObject(result2); String errorCode2 = newObj2"error_code".Value; if (errorCode2 = "0") Debug.WriteLine("成功"); Debug.Write
18、Line(newObj2); else /Debug.WriteLine("失敗"); Debug.WriteLine(newObj2"error_code".Value+":"+newObj2"reason".Value); /3.銀行賬戶黃金 string 3 = "web:8080/finance/gold/bankgold" var parameters3 = new Dictionary<string, string>(); parameters3.Add("ke
19、y", appkey);/你申請的key string result3 = sendPost(3, parameters3, "get"); JsonObject newObj3 = new JsonObject(result3); String errorCode3 = newObj3"error_code".Value; if (errorCode3 = "0") Debug.WriteLine("成功"); Debug.WriteLine(newObj3); else /Debug.WriteLin
20、e("失敗"); Debug.WriteLine(newObj3"error_code".Value+":"+newObj3"reason".Value); / <summary> / Http (GET/POST) / </summary> / <param name="">請求</param> / <param name="parameters">請求參數</param> / <param na
21、me="method">請求方法</param> / <returns>響應內容</returns> static string sendPost(string , IDictionary<string, string> parameters, string method) if (method.ToLower() = "post") HttpWebRequest req = null; HttpWebResponse rsp = null; System.IO.Stream reqStream =
22、null; try req = (HttpWebRequest)WebRequest.Create(); req.Method = method; req.KeepAlive = false; req.ProtocolVersion = HttpVersion.Version10; req.Timeout = 5000; req.ContentType = "application/x-www-form-encoded;charset=utf-8" byte postData = Encoding.UTF8.GetBytes(BuildQuery(parameters, &
23、quot;utf8"); reqStream = req.GetRequestStream(); reqStream.Write(postData, 0, postData.Length); rsp = (HttpWebResponse)req.GetResponse(); Encoding encoding = Encoding.GetEncoding(rsp.CharacterSet); return GetResponseAsString(rsp, encoding); catch (Exception ex) return ex.Message; finally if (re
24、qStream != null) reqStream.Close(); if (rsp != null) rsp.Close(); else /創(chuàng)建請求 HttpWebRequest request = (HttpWebRequest)WebRequest.Create( + "?" + BuildQuery(parameters, "utf8"); /GET請求 request.Method = "GET" request.ReadWriteTimeout = 5000; request.ContentType = "te
25、xt/html;charset=UTF-8" HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream myResponseStream = response.GetResponseStream(); StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"); /返回內容 string retString = myStreamReader.Rea
26、dToEnd(); return retString; / <summary> / 組裝普通文本請求參數。 / </summary> / <param name="parameters">Key-Value形式請求參數字典</param> / <returns>編碼后的請求數據</returns> static string BuildQuery(IDictionary<string, string> parameters, string encode) StringBuilder post
27、Data = new StringBuilder(); bool hasParam = false; IEnumerator<KeyValuePair<string, string>> dem = parameters.GetEnumerator(); while (dem.MoveNext() string name = dem.Current.Key; string value = dem.Current.Value; / 忽略參數名或參數值為空的參數 if (!string.IsNullOrEmpty(name)/&& !string.IsNull
28、OrEmpty(value) if (hasParam) postData.Append("&"); postData.Append(name); postData.Append("="); if (encode = "gb2312") postData.Append(HttpUtility.Encode(value, Encoding.GetEncoding("gb2312"); else if (encode = "utf8") postData.Append(HttpUtility
29、.Encode(value, Encoding.UTF8); else postData.Append(value); hasParam = true; return postData.ToString(); / <summary> / 把響應流轉換為文本。 / </summary> / <param name="rsp">響應流對象</param> / <param name="encoding">編碼方式</param> / <returns>響應文本</ret
30、urns> static string GetResponseAsString(HttpWebResponse rsp, Encoding encoding) System.IO.Stream stream = null; StreamReader reader = null; try / 以字符流的方式讀取HTTP響應 stream = rsp.GetResponseStream(); reader = new StreamReader(stream, encoding); return reader.ReadToEnd(); finally / 釋放資源 if (reader !=
31、null) reader.Close(); if (stream != null) stream.Close(); if (rsp != null) rsp.Close(); 代碼 PHP代碼 /* * c遠程傳輸工具 */public function post_c($,$body,$header,$type='POST') $ch = c_init(); c_setopt($ch,COPT_,$); c_setopt($ch,COPT_HEADER,0);/0只要正文 c_setopt($ch,COPT_TIMEOUT,5);/設置超時時間 c_setopt($ch,COP
32、T_CONNECTTIMEOUT,5); /將c_exec()獲取的信息以文件流的形式返回,而不是直接輸出。 c_setopt($ch,COPT_RETURNTRANSFER,1); /增加header頭信息 / array_push($header,'Accept:application/json'); / array_push($header,'Content-Type:application/json'); / array_push($header,'http:multipart/form-data'); if(count($body)&g
33、t;0) c_setopt($ch,COPT_POSTFIELDS,$body); if(count($header)>0) c_setopt($ch,COPT_HTTPHEADER,$header); /設置上傳文件相關 c_setopt($ch,COPT_FOLLOWLOCATION,true); c_setopt($ch,COPT_MAXREDIRS,3);/遞歸 c_setopt($ch,COPT_SSL_VERIFYPEER,false);/ 對認證證書來源的檢查 c_setopt($ch,COPT_SSL_VERIFYHOST,0);/ 從證書中檢查SSL加密算法 switc
34、h ($type) case 'GET': c_setopt($ch,COPT_HTTPGET,1); break; case 'POST': c_setopt($ch,COPT_POST,1); break; case 'PUT': c_setopt($ch,COPT_CUSTOMREQUEST,'PUT'); break; case 'DELETE': c_setopt($ch,COPT_CUSTOMREQUEST,'DELETE'); break; /上傳文件相關設置 c_setopt($ch
35、,COPT_ENCODING,'gzip'); c_setopt($ch,COPT_USERAGENT,'SSTS Browser/1.0'); c_setopt($ch,COPT_USERAGENT,'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)');/ 模擬用戶使用的瀏覽器 if(c_errno($ch) return c_error($ch); $content = c_exec($ch); c_close($ch);/關閉c資源,并且釋放系統(tǒng)資源 $resu
36、lt = json_decode($content,true); if(!empty($result) return $result; else return $content; 代碼 C/C+代碼 /*編譯指令$ /opt/sybase/OCS-16_0/bin/cpre64 -m teststu.cp$ cc -m64 -g -DSYB_LP64 -I. -I/opt/sybase/OCS-16_0/include teststu.c /opt/sybase/OCS-16_0/include/sybesql.c -L/opt/sybase/OCS-16_0/lib -lsybct64 -l
37、sybtcl64 -lsybcs64 -lsybcomn64 -lsybintl64 -lsybunic64 -rdynamic -ldl -lnsl -lm -o teststu*/#include <stdio.h> /*建立通訊區(qū)域*/EXEC SQL INCLUDE SQLCA;/* * These tokens must be declared in a declare section* because they are used in declare sections below.*/EXEC SQL BEGIN DECLARE SECTION;#define TYPE
38、SIZE 13#define TIDSIZE 6EXEC SQL END DECLARE SECTION; #define EOLN '0'/* * Forward declarations of the error and message handlers and* other subroutines called from main().*/void error_handler();void warning_handler(); intmain(int argc, char *argv)/*聲明宿主變量*/ EXEC SQL BEGIN DECLARE SECTION; /
39、* storage for login name and password. */ char username30; char sname30; char password30; char server30; EXEC SQL END DECLARE SECTION;/*錯誤處理*/ EXEC SQL WHENEVER SQLERROR CALL error_handler(); EXEC SQL WHENEVER SQLWARNING CALL warning_handler(); EXEC SQL WHENEVER NOT FOUND CONTINUE;/*連接到 SQL SERVER 服
40、務器*/ /* * Copy the user name and password defined in sybsqlex.h to * the variables declared for them in the declare section. */ strcpy(username, "mymotif"); strcpy(password, "wxwpxh"); strcpy(server, "MYMOTIFVOSTRO145480"); EXEC SQL CONNECT :username IDENTIFIED BY :pass
41、word using :server; EXEC SQL USE testdb; EXEC SQL DECLARE c1 CURSOR FOR SELECT SNAME FROM STUDENT; EXEC SQL OPEN c1; printf("name in table studentn"); do EXEC SQL FETCH c1 INTO :sname; if (sqlca.sqlcode != 0) break; printf( "student name = %sn", sname ); while ( 1 ); EXEC SQL CLO
42、SE c1; return(0); 秦皇島同城購 侭侰侮 /*錯誤處理程序*/* void error_handler()* * Displays error codes and numbers from the SQLCA and exits with* an ERREXIT status. */voiderror_handler(void) fprintf(stderr, "n* SQLCODE=(%ld)", sqlca.sqlcode); if (sqlca.sqlerrm.sqlerrml) fprintf(stderr, "n* ASE Error &
43、quot;); fprintf(stderr, "n* %s", sqlca.sqlerrm.sqlerrmc); fprintf(stderr, "nn"); exit(-1); /* void warning_handler()* * Displays warning messages.*/voidwarning_handler(void) if (sqlca.sqlwarn1 = 'W') fprintf(stderr, "n* Data truncated.n"); if (sqlca.sqlwarn3 = &
44、#39;W') fprintf(stderr, "n* Insufficient host variables to store results.n"); return;代碼 Log4j配置 <!- 日志jar -> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </dependency>導入這個包,會引入下面兩個jar<!-spring 的基本jar包 ->
45、; <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> </dependency> <!- commons-login是必須的,而且沒有依賴,是獨立的包 -> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging-api</artifactId> <version>1.1</version> </dependency><dependency><!- transactionManager實務管理的時候,需要這個jar包 -> <groupId>org.springframework</groupId> <ar
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 江蘇省東??h2025年初三下學期統(tǒng)測化學試題試卷含解析
- 江蘇省徐州市六校-重點達標名校2025屆初三七校聯(lián)考化學試題試卷含解析
- 成都理工大學工程技術學院《大學英語(5)》2023-2024學年第一學期期末試卷
- 西藏自治區(qū)拉薩市八校2025年高三歷史試題2月聯(lián)考試題含解析
- 廣東省河源市重點中學2025屆下學期高三數學試題高考仿真考試試卷含解析
- 延安職業(yè)技術學院《微生物生理學》2023-2024學年第二學期期末試卷
- 西安汽車職業(yè)大學《朝鮮(韓國)語視聽說》2023-2024學年第二學期期末試卷
- 廣東海洋大學《行動學習》2023-2024學年第二學期期末試卷
- 上海出版印刷高等??茖W?!侗w楷行書》2023-2024學年第一學期期末試卷
- 山東省金鄉(xiāng)縣金育高級中學2024-2025學年高三第二次適應性考試物理試題試卷含解析
- 2024遼寧能源集團所屬能源投資集團招聘3人筆試參考題庫附帶答案詳解
- 2025年度馬鈴薯種薯產業(yè)扶貧與鄉(xiāng)村振興合作合同4篇
- 《退役鋰電池清潔循環(huán)利用技術規(guī)范》編制說明
- 交通法律法規(guī)知識培訓
- 夜間安全施工培訓
- 零售藥店醫(yī)療保障定點管理暫行辦法
- 道路工程交通安全設施施工方案及保障措施
- 花粉購銷合同范例
- 大學生就業(yè)規(guī)劃西部計劃
- 柑橘品種改良研究
- CSMS助力教師構建中職數學高效課堂的案例研究
評論
0/150
提交評論