❶ 求教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);
。。。