找回密码
 加入
搜索
查看: 3781|回复: 2

[网络通信] post 上传图片,如何上传标准multipart/form-data编码方式,HTTP RFC1867协议 格式?

[复制链接]
发表于 2014-11-20 19:32:11 | 显示全部楼层 |阅读模式
HTTP接口说明是这样的:

上传图片返回结果.
请求URL
http://api.ysdm.net/create.json(扩展名支持.txt|.xml)
支持格式
txt,xml,json
HTTP请求方式
POST
请求参数
        必选        类型        说明
username        true        string        用户名。
password        true        string        用户密码。(支持32位MD5)
typeid        true        int        题目类型
softid        true        int        软件ID,开发者可自行申请。
softkey        true        string        软件KEY,开发者可自行申请。
image        true        byte        题目截图或原始图二进制数据。注意事项
1.开发时需要修改HTTP请求默认超时时间,具体数值需要大于任务超时的timeout参数。
2.POST上传请求包括图片上传格式为标准multipart/form-data编码方式,HTTP RFC1867协议
返回结果
正确返回
SON:{"Result":"答题结果","Id":"题目Id(报错使用)"}
错误返回
JSON:{"Error":"错误提示信息","Error_Code":"","Request":""}

我的代码是这样的:
Dim $pic_file = @ScriptDir & "\1.png"
Dim $yunsu_username = 'qiuzhengyu'
Dim $yunsu_author = 'qiuzhengyu'
Dim $yunsu_password = 'a111222'
Dim $yunsu_typeid = '3040';四位   3050 为五位
Dim $yunsu_timeout = '60'
Dim $yunsu_softid = '2399'
Dim $yunsu_softkey = 'e059bab0823f4411a33807e0c4d3d18c'
Dim $yunsu_image;二进制数据


$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")

$temp =  yunsu_recognize_pic()
MsgBox(0,"",$temp)  ;收不到返回参数
$oHTTP = 0


Func yunsu_recognize_pic()
        Local $file = FileOpen($pic_file,16)
        Local $temp = FileRead($file)
        FileClose($file)
        
        $oHTTP.Open("post", "http://api.ysdm.net/create.json",False)
    $oHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded") 

        $oHTTP.Send("username="&$yunsu_username&"&password="&$yunsu_password&"&typeid="&$yunsu_typeid & _
                    "&softid="&$yunsu_softid&"&softkey="&$yunsu_softkey&"&image="&$temp)
        Local $temp = $oHTTP.responseBody
        $temp = BinaryToString($temp,4)
        Return $temp
EndFunc
但是得不到正确数据,是不是这个图片上传的这里出问题了,求帮忙瓦
 楼主| 发表于 2014-11-25 12:23:17 | 显示全部楼层
期待大神出现。。。
 楼主| 发表于 2014-11-28 16:40:08 | 显示全部楼层
期待大神出现。。。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-27 12:19 , Processed in 0.074816 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表