❶ 求教URL發送jsON格式數據問題
url是要訪問的地址,method是請求方式可以是POST或者GET,params是後面的參數比如?aa=11&bb=22publicStringconnctionURL_Params(Stringurl,Stringmethod,Stringparams){StringBufferbufferRes=newStringBuffer();url=url+params;
❷ get的url傳參書寫格式和 post的send(string)傳參格式各是怎樣的
給你轉點來自網路的
XMLHttpRequest.open()
初始化 HTTP 請求參數
語法
open(method, url, async, username, password)
method 參數是用於請求的 HTTP 方法。值包括 GET、POST 和 HEAD。
url 參數是請求的主體。大多數瀏覽器實施了一個同源安全策略,並且要求這個 URL 與包含腳本的文本具有相同的主機名和埠。
async 參數指示請求使用應該非同步地執行。如果這個參數是 false,請求是同步的,後續對 send() 的調用將阻塞,直到響應完全接收。如果這個參數是 true 或省略,請求是非同步的,且通常需要一個 onreadystatechange 事件句柄。
username 和 password 參數是可選的,為 url 所需的授權提供認證資格。如果指定了,它們會覆蓋 url 自己指定的任何資格。
request.open("GET", "serverjson.php?number=" + document.getElementById("keyword").value);
這時open(method,url,async,username,password)的參數對應關系分別如下:
method:"GET"
url:"serverjson.php?number=" + document.getElementById("keyword").value;//字元串組合
async:默認值true
username:未指定
password:未指定
❸ java遠程請求url地址,並且要求傳遞參數,後獲得該遠程url返回的json類型的數據,應該怎麼實現
url是要訪問的地址,method是請求方式可以是POST或者GET,params是後面的參數比如?aa=11&bb=22
publicStringconnctionURL_Params(Stringurl,Stringmethod,Stringparams){
StringBufferbufferRes=newStringBuffer();
url=url+params;
try{
URLrealUrl=newURL(url);
HttpURLConnectionconn=(HttpURLConnection)realUrl.openConnection();
//請求方式
conn.setRequestMethod(method);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.connect();
InputStreamin=conn.getInputStream();
BufferedReaderread=newBufferedReader(newInputStreamReader(in,"UTF-8"));
StringvalueString=null;
while((valueString=read.readLine())!=null){
bufferRes.append(valueString);
}
read.close();
in.close();
in=null;
if(conn!=null){
//關閉連接
conn.disconnect();
}
}catch(Exceptione){
e.printStackTrace();
}
returnbufferRes.toString();
}
❹ post請求怎麼把json參數傳遞
http post請求的json類型參數獲取 方法:request.getParameter("json的key")這樣就可以
❺ Android如何傳輸參數給一個url介面 參數是json格式
一般傳輸參數使用json類型或者map類型都是使用post方法。
使用json數據格式發送信息向伺服器端:
HttpClient httpClient = new DefaultHttpClient();
try {
HttpPost httpPost = new HttpPost(BASIC_URL + url);
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>();
JSONObject jsonObject = new JSONObject();
JSONObject jsonObject2 = new JSONObject();
jsonObject.put("uemail", userbean.getEmail());
jsonObject.put("password", userbean.getPassword());
jsonObject2.put("userbean", jsonObject);
nameValuePair.add(new BasicNameValuePair("jsonString", jsonObject
.toString()));
Log.i("lifeweeker", jsonObject2.toString());
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
}
❻ 使用Post方法傳遞json參數有哪些方式
ajax,或者from表單 記得ajax 可以把from表單變成json穿到後台
❼ 使用java發送一個post請求怎麼傳遞json參數
這樣就能接到了
❽ json的本質是字元串,那麼可以通過url加參數的方式傳遞json字元串嗎
如果是form的get方式的話,建議不要,因為json字元串的某些特殊符號容易引起請版求錯誤,接收權數據被截斷的問題
解決,用一個input 或者 textArea 存放json的值,但建議最好用post方式
如果是ajax請求的話
$.ajax({
type:"post",
url:url,
dateType:"json",
data:{'變數名1':變數值1,'變數名2':變數值2,...},//這種方式傳遞
success:function(data){
}
});
❾ 我正在寫介面,用POST怎樣接收json傳遞過來的值
前台
varjson1={name:"aaa",age:18};
$.ajax({
type:"POST",
url:"sys_addOrder",
cache:"false",
data:{obj1:json1},
dataType:'json',
success:function(json){
alert("提交成功");
}
});
後台
$json1=$_POST['obj1'];
echo$json1.name;
❿ 如何post一個json格式的數據
在Android/java平台上實現POST一個json數據:
JSONObject jsonObj = new JSONObject();
jsonObj.put("username", username);
jsonObj.put("apikey", apikey);
// Create the POST object and add the parameters
HttpPost httpPost = new HttpPost(url);
StringEntity entity = new StringEntity(jsonObj.toString(), HTTP.UTF_8);
entity.setContentType("application/json");
httpPost.setEntity(entity);
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(httpPost);
用curl可執行如下命令:
curl -l -H "Content-type: application/json" -X POST -d '{"phone":"13521389587","password":"test"}'
用jQuery:
$.ajax({
url:url,
type:"POST",
data:data,
contentType:"application/json; charset=utf-8",
dataType:"json",
success: function(){
...
}
})
PHP用cUrl實現:
$data = array("name" => "Hagrid", "age" => "36");
$data_string = json_encode($data);
$ch = curl_init(');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
。。。