postjson的简单介绍
本篇文章给大家谈谈postjson,以及对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
postjson和getjson的区别
get和post顾名思义,两种提交方式,getjson则是向后卜老台定了一个要求,返回的数据必须是json,否则回调函数里的XHR对象为空,$get,$post,$getjson三个方法最后调用的都是$ajax,只不过jquery对这三个方型雀升法进行岁纤了简单的封装。
vb6如何post json数据?
Public Function Ajax_Post(ByVal StrUrl As String, Optional ByVal StrData As String, Optional ByVal Index As Long) As Variant
On Error GoTo MyError:
Dim Object As Object, S As String, B() As Byte
Set Object = CreateObject("Microsoft.XMLHTTP")
尺隐蠢 Object.Open "POST", StrUrl, True
Object.setRequestHeader "Content-Length", Len(Ajax_Post)
Object.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
Object.send (StrData)
Do Until Object.readyState = 4
DoEvents
Loop
Select Case Index
Case 1: S = Object.responseText: Ajax_Post = S '返回字符串
Case 2: B = Object.responseBody: Ajax_Post = B '返回二进制
Case 3: S = BytesToStr(Object.responseBody): Ajax_Post = S '二进制转字符串[直接返回字串出现乱码时尝试]
Case Else: Ajax_Post = vbNullString '无效的返回
携启 End Select
Set Object = Nothing '释放空间
Exit Function
MyError:
Ajax_Post = vbNullString '出错返回空
End Function
Function BytesToStr(ByVal vIn) As String
Dim strReturn As String, ThisCharCode As String, NextCharCode As String, I As Long
For I = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn, I, 1))
If ThisCharCode 陵陪 H80 Then
strReturn = strReturn Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn, I + 1, 1))
strReturn = strReturn Chr(CLng(ThisCharCode) * H100 + CInt(NextCharCode))
I = I + 1
End If
Next
BytesToStr = strReturn
End Function
Private Sub Command1_Click()
Dim Url As String, Key As Variant, JsonKey As String
Url = ""
Key = Array("wd=123", "aa=456", "bb=789", "cc=901")
JsonKey = Join(Key, "")
MsgBox Ajax_Post(Url, JsonKey, 1)
End Sub
[img]如何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);
。。。
关于postjson和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。