VBA HTTP POST参数不正确 [英] VBA HTTP POST Parameter Incorrect

查看:70
本文介绍了VBA HTTP POST参数不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是VBA的新手,所以这可能是我的问题.我正在尝试执行从Excel到Web服务的HTTP POST,并且我可以很开心地进行POST,直到更改代码以便将内容发布到消息中为止,这时出现以下错误:

I am new to VBA so this is probably my problem. I am trying to perform a HTTP POST from Excel to a web service, and I can POST quite happily, until I change the code so that I am posting content in my message, at which point I get the following error:

运行时错误'-2147024809(80070057)':

Run-time error '-2147024809 (80070057)':

参数不正确.

我的代码如下:

Dim oHttp As Object
Set oHttp = CreateObject("MSXML2.XMLHTTP.6.0")
Call oHttp.Open("POST", url, False)
oHttp.setRequestHeader "Content-Type", "application/text"
oHttp.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
Call oHttp.send(content)
httpPOST = oHttp.responseText

杀死代码的行是oHttp.send-如果我不传递任何内容,那很好,只要我将内容放在这里就感到不高兴.

The line which is killing the code is the oHttp.send - if I do not pass any content then it is fine, as soon as I put content here it is unhappy.

content参数是一个大字符串,包含逗号分隔的文本,并包含换行符.我认为这就是为什么我不满意的原因,如果我将字符串更改为一个简短的"Hello"字样,那么发送成功,应用程序会很高兴地进入下一行,然后再遇到运行时错误:

The content parameter is a large string containing comma separated text and includes line feeds. I think this is why it is unhappy, if I change the string to simply a short "Hello" then the send is sucessful and the application happily makes it to the next line, before hitting the run-time error:

完成此操作所需的数据尚不可用

The data necessary to complete this operation is not yet available

所以我想我的问题是,如何将一大段文本发布到服务器上?

So I guess my question is, how do I POST a large block of text to a server?

谢谢

推荐答案

感谢注释,我成功地通过将字符串转换为二进制数组然后将二进制数组发送过来来使其正常工作.

Thanks for the comments, I managed to get it to work by converting the string to a binary array and then send the binary array over.

这篇关于VBA HTTP POST参数不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆