vb post 多个参数的问题?

shing1x 2018-07-06 11:20:44
大家帮我看一下是什么问题?
php只返回“用户名”,但"aaa"显示收不到、显示不了。
因为还要传输图片base64的数据,所以要用post方式。



vb

Set HttpClient = CreateObject("Microsoft.XMLHTTP")
HttpClient.Open "POST", "http://127.0.0.1/test.php", False
HttpClient.setRequestHeader "Content-Type", "text/xml; charset=gb2312"
HttpClient.send "f_name=aaa&f_code=123456"



<?php
//强制浏览器编码
@header('Content-type: text/html;charset=gb2312');

//设置时区
date_default_timezone_set('PRC');


$s_name = trim($_POST['f_name']);
$s_code = $_POST['f_code'];

echo "用户名" . $s_name;
?>
...全文
533 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
shw014 2018-12-12
  • 打赏
  • 举报
回复
网上找的 URLEncode 函数
Public Function URLEncode(ByVal strParameter As String) As String
Dim s As String
Dim I As Integer
Dim intValue As Integer
Dim TmpData() As Byte
s = ""
TmpData = StrConv(strParameter, vbFromUnicode)
For I = 0 To UBound(TmpData)
intValue = TmpData(I)
If (intValue >= 48 And intValue <= 57) Or _
(intValue >= 65 And intValue <= 90) Or _
(intValue >= 97 And intValue <= 122) Then
s = s & Chr(intValue)
ElseIf intValue = 32 Then
s = s & "+"
Else
s = s & "%" & Hex(intValue)
End If
Next I
URLEncode = s
End Function

第四行代码改成
HttpClient.Send "f_name=" & URLEncode("中文") & "&f_code=123456"
shw014 2018-12-12
  • 打赏
  • 举报
回复
第三行 Content-Type 改一下
HttpClient.setRequestHeader "Content-Type", "application/x-www-form-urlencoded; charset=gb2312"
cofee54677 2018-12-03
  • 打赏
  • 举报
回复
学习了 ,这个是VB net代码吧
现在还是人类 2018-07-17
  • 打赏
  • 举报
回复
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<?php
//强制浏览器编码
@header('Content-type: text/html;charset=gb2312');

//设置时区
date_default_timezone_set('PRC');


$s_name = trim($_POST['f_name']);
$s_code = $_POST['f_code'];

echo "用户名" . $s_name;
?></body>
</html>

而且要注意你的PHP配置,default_charset = "gb2312"
笨狗先飞 2018-07-06
  • 打赏
  • 举报
回复
如果全部站内的话,全用gb2312编码统一好了,如果用了utf8,那在vb端就要转码了
shing1x 2018-07-06
  • 打赏
  • 举报
回复
请问中文乱码怎么解决?
笨狗先飞 2018-07-06
  • 打赏
  • 举报
回复
post需要用这个header
HttpClient.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"

1,502

社区成员

发帖
与我相关
我的任务
社区描述
VB 网络编程
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧