用MSXML2.XMLHTTP上传文件,出现的问题,搞了两天了,晕啊
我用MSXML2.HTTPXML上传文件给Kimi,kimi要求必须:"Content-Type","multipart/form-data",拼接这个body好麻烦,很久都没有成功,请大侠指点:lcDescription="lcDescription"
lcFilePath = GETFILE()
lcFileContent =FILETOSTR(lcFilePath)
lcApiUrl="https://api.
lcApiKey="我的APIKEY"
*// 创建XMLHTTP对象实例
loXmlHttp = CREATEOBJECT("MSXML2.XMLHTTP")
*// 设置请求方法和URL
loXmlHttp.open('POST', m.lcApiUrl, .F.)
*// 构造boundary用于multipart/form-data
lcBoundary ="--"+ALLTRIM(SYS(2))+ALLTRIM(STR(RAND(9999)))
lcContentType = "multipart/form-data; boundary=" + lcBoundary
*// 构造表单数据
lcFormData = '--' + lcBoundary + CHR(13) + CHR(10) + ;
'Content-Disposition: form-data; name="files"; filename="选择的文件.TXT"' + CHR(13) + CHR(10) + ;
'Content-Type: multipart/form-data' + CHR(13) + CHR(10) + CHR(13) + CHR(10) +;
lcFileContent + CHR(13) + CHR(10) +;
'--' + lcBoundary + CHR(13) + CHR(10) + ;
'Content-Disposition: form-data; name="descriptions"' + CHR(13) + CHR(10) + CHR(13) + CHR(10) + ;
lcDescription + CHR(13) + CHR(10) + ;
'--' + lcBoundary + '--' + CHR(13) + CHR(10)
*// 设置请求头
loXmlHttp.setRequestHeader("Content-Type", lcContentType)
loXmlHttp.setRequestHeader("Authorization", "Bearer " + lcApiKey)
*// 发送POST请求
loXmlHttp.send(lcFormData)
[此贴子已经被作者于2024-4-5 01:46编辑过]