鏂版墜蹇呭锛屽ぇ鐗涙暣鐞嗙殑鎺ュ彛娴嬭瘯鐭ヨ瘑鐐规€荤粨
Posted 浜戞祴瀛﹂櫌
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了鏂版墜蹇呭锛屽ぇ鐗涙暣鐞嗙殑鎺ュ彛娴嬭瘯鐭ヨ瘑鐐规€荤粨相关的知识,希望对你有一定的参考价值。
璇磋捣鎺ュ彛娴嬭瘯锛岀綉涓婃湁寰堝渚嬪瓙锛屼絾鏄綋鍒濆仛涓烘柊鎵嬬殑鎴戞潵璇达紝鐪嬩簡涓嶄笉鐭ラ亾浠栦滑璇寸殑浠€涔堬紝瑙夊緱鎺ュ彛娴嬭瘯锛屽ソ楂樺ぇ涓娿€傝涓哄浼氫簡鎺ュ彛娴嬭瘯灏辫兘灞屼笣閫嗚锛岃蛋涓婁汉鐢熷穮宄帮紝杩庡ǘ鐧藉瘜缇庛€傚洜姝?/span>瀛︿簡鐐瑰紑鍙戠煡璇嗗悗锛屽彂鐜版帴鍙f祴璇曞叾瀹為兘鏄汉浠帺鐨勫悕璇嶇舰浜嗐€?/span>鎺ュ彛娴嬭瘯锛岀湡蹇冨緢绠€鍗曘€?/span>瀹冨彧涓嶈繃鏄暟鎹紶閫掓槸涓€绉嶈〃鐜拌€屽凡銆?/span>
涓€銆佽姹傛ā鍨?/span>
鐪嬩笅鍥句腑鈥淎鈥濈嚎锛屽彲浠ョ悊瑙d负鎺ュ彛灏辨槸涓€涓數鐏殑寮€鍏筹紝瀹冨湪鎺ュ彛閲岄潰缁欎綘鎻愪緵浜嗕竴涓弬鏁帮紝鍙傛暟鐨勫€间竴涓槸鈥滃紑鈥濓紝涓€涓槸鈥滃叧鈥濄€?/span>
璇磋捣鏉ワ紝鎬庝箞鎵嶈兘璁╃伅浜紵涓€涓伅澶存帴涓ゆ牴绾匡紝涓€鏍圭嚎鎺ョ伀绾匡紝涓€鏍圭嚎鎺ラ浂绾胯繖鏃剁伅灏变寒浜嗐€傚弽涔嬶紝涓嶆帴闆剁嚎銆佺伀绾跨伅灏辩伃浜嗐€?/span>
鍏跺疄鎺ュ彛鍛紝灏辨妸杩欎簺澶嶆潅鐨勬搷浣滅畝鍖栦簡锛岃浣犵湅鍒扮殑灏卞彧鏈変竴涓紑鍏筹紝鑰屼綘鏉ユ搷浣滆繖涓紑鍏冲氨濂戒簡銆傛垜浠仛鎺ュ彛娴嬭瘯涔熷彧闇€瑕佹祴璇曡繖涓紑鍏冲氨瀹屾垚浠诲姟浜嗭紝鎺ュ彛娴嬭瘯灏辨槸杩欎箞绠€鍗曘€?/span>
1銆佸綋浣犺闂€渉ttp://127.0.0.1:8080/light?opt=open鈥濓紝璁╅浂绾裤€佺伀绾胯繛閫氾紝姝ゆ椂鐏寒銆?/span>
2銆佸綋浣犺闂€渉ttp://127.0.0.1:8080/light?opt=close鈥濓紝璁╅浂绾裤€佺伀绾挎柇寮€锛屾鏃剁伅鐏€?/span>
浜屻€佽姹傜粨鏋?/span>
鐪嬪埌杩欓噷鎴戜滑澶ц嚧灏辨槑鐧戒簡鎺ュ彛娴嬭瘯鏄€庝箞涓€鍥炰簨浜嗐€傛帴涓嬫潵闇€瑕佺悊瑙d竴涓婬TTP鐨刄RL鏄€庝箞缁勬垚涓轰竴涓帴鍙g殑銆傚鍥撅細
1銆佷竴涓猆RL灏辨槸涓€涓帴鍙o細鎺ュ彛澶ц嚧浼氬垎涓轰竴涓嬪嚑涓儴鍒嗭細
鈶犺姹傚崗璁細
-
http 鈥?鏅€氱殑http璇锋眰 -
https 鈥?鍔犲瘑鐨刪ttp璇锋眰锛屼紶杈撴暟鎹洿鍔犲畨鍏?/span> -
ftp 鈥?鏂囦欢浼犺緭鍗忚锛屼富瑕佺敤鏉ヤ紶杈撴枃浠?/span>
-
鈥渙pt鈥?鈥漮pen鈥?/span> -
鈥渦se鈥?鈥漼y鈥?/span> -
鈥減wd鈥?鈥?23456鈥?/span>
-
http璇锋眰鏂瑰紡
GET --- 閫氳繃璇锋眰URI寰楀埌璧勬簮
POST --- 鐢ㄤ簬娣诲姞鏂扮殑鍐呭
PUT --- 鐢ㄤ簬淇敼鏌愪釜鍐呭
DELETE --- 鍒犻櫎鏌愪釜鍐呭
CONNECT --- 鐢ㄤ簬浠g悊杩涜浼犺緭锛屽浣跨敤SSL
OPTIONS --- 璇㈤棶鍙互鎵ц鍝簺鏂规硶
PATCH --- 閮ㄥ垎鏂囨。鏇存敼
PROPFIND (wedav) --- 鏌ョ湅灞炴€?/span>
PROPPATCH (wedav) --- 璁剧疆灞炴€?/span>
MKCOL (wedav) --- 鍒涘缓闆嗗悎锛堟枃浠跺す锛?/span>
COPY (wedav) --- 鎷疯礉
MOVE (wedav) --- 绉诲姩
LOCK (wedav) --- 鍔犻攣
UNLOCK (wedav) --- 瑙i攣
TRACE --- 鐢ㄤ簬杩滅▼璇婃柇鏈嶅姟鍣?/span>
HEAD --- 绫讳技浜嶨ET, 浣嗘槸涓嶈繑鍥瀊ody淇℃伅锛岀敤浜庢鏌ュ璞℃槸鍚﹀瓨鍦紝浠ュ強寰楀埌瀵硅薄鐨勫厓鏁版嵁
-
http璇锋眰澶?/span>
Accept:image/gif.image/jpeg./
Accept-Language:zh-cn
Connection:Keep-Alive
Host:localhost
User-Agent:Mozila/4.0(compatible:MSIE5.01:Windows NT5.0)
Accept-Encoding:gzip,deflate.
-
http璇锋眰浣?/span>
-
json鏍煎紡 -
xml鏍煎紡 -
html鏍煎紡 -
浜岃繘鍒舵牸寮? 澶氭暟鐢ㄤ簬鍥剧墖 ) -
瀛楃涓叉牸寮?/span>
package com.yy.test;
import net.sf.json.JSONObject;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
// 鎺ュ彛鐨勫悕绉颁笌璺緞锛寀rlPatterns涓殑/light锛屽氨鏄鍦ㄨ緭鍏ュ湴鍧€涓巌p鍚庯紝瀹氫箟鐨勬帴鍙e悕瀛梙ttp://127.0.0.1:8080/light
@WebServlet(name = "light", urlPatterns = "/light")
public class light extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 鑾峰彇opt鐨勫€?nbsp;
String opt = request.getParameter("opt");
// 鏂板缓杩斿洖json鐨勫璞?nbsp;
JSONObject json = new JSONObject();
// 鍒ゆ柇opt鏈夋病鏈夊€?nbsp;
if (null != opt) {
// 瀹氫箟杩斿洖鐨勮姹傚ご锛岀被鍨嬫槸json锛岀紪鐮佹槸utf-8
response.setContentType("application/json; charset=UTF-8");
// 瀹氫箟杩斿洖鐨勫璞★紝鐢ㄥ畠鏉ュ皢json杈撳嚭
PrintWriter out = response.getWriter();
// 鍒ゆ柇opt鐨勫€兼槸涓嶆槸open
if ("open".equals(opt)) {
json.put("msg", "寮€鐏暒锛?);
out.println(json);
}
// 鍒ゆ柇opt鐨勫€兼槸涓嶆槸close
else if ("close".equals(opt)) {
json.put("msg", "鍏崇伅鍟︼紒");
out.println(json);
}
}
}
}
-
濡傛灉鏄€漮pen鈥濆氨杩斿洖鈥濆紑鐏暒锛佲€?/span> -
濡傛灉鏄€漜lose鈥濆氨杩斿洖鈥濆叧鐏暒锛佲€?/span>
to --- 缈昏瘧鎴愬摢鍥借瑷€
query --- 缈昏瘧閮藉唴瀹?/span>
import requests
# 鎺ュ彛鐨剈rl
url = "http://fanyi.baidu.com/v2transapi"
# 鎺ュ彛鐨勫弬鏁?nbsp;
params = {
"from":"en",
"to":"zh",
"query": "test"
}
# 鍙戦€佹帴鍙?nbsp;
r = requests.request("post", url, params=params)
# 鎵撳嵃杩斿洖缁撴灉
print(r.text)
# 鍏跺疄鍒颁笂闈㈠氨宸茬粡瀹屼簡锛屽洜涓虹櫨搴︿笉鏄垜鑷繁鍐欑殑鎺ュ彛锛屼负浜嗚缁撴灉鐪嬬殑鏇村姞娓呮涓€鐐癸紝鎴戝彇鏉ョ炕璇戠殑瀛楁
import json
d = json.loads(r.text)
print(d['liju_result']['tag'])
杩斿洖缁撴灉
['璇曢獙', '娴嬮獙', '鑰冮獙', '鍖栭獙', '鑰冩煡', '鍙楄瘯楠?, '鍙楁祴楠?, '鍙楄€冮獙', '娴嬪緱缁撴灉']
鍙互璇曠潃灏?span class="code-snippet__string">"query"鐨勫弬鏁版敼鎴?span class="code-snippet__string">"student"锛岃繑鍥炵粨鏋滀篃闅忎箣鏀瑰彉
import requests
url = "http://fanyi.baidu.com/v2transapi"
params = {
"from":"en",
"to":"zh",
"query": "student" # 鎴戞敼浜嗚繖閲?nbsp;
}
r = requests.request("post", url, params=params)
import json
d = json.loads(r.text)
print(d['liju_result']['tag'])
杩斿洖缁撴灉
['涓鐢?, '瀛︾敓', '澶у鐢?, '鐮旂┒鑰?, '瀛﹁€?]
以上是关于鏂版墜蹇呭锛屽ぇ鐗涙暣鐞嗙殑鎺ュ彛娴嬭瘯鐭ヨ瘑鐐规€荤粨的主要内容,如果未能解决你的问题,请参考以下文章
Dubbo鎺ュ彛涓嶇煡閬撴€庝箞娴嬶紵鏁欎綘涓夎浠g爜瀹炵幇dubbo鎺ュ彛娴嬭瘯