Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MSXML2.XMLHTTP将数据发送到PHP脚本_Php_Mysql_Vba_Outlook - Fatal编程技术网

MSXML2.XMLHTTP将数据发送到PHP脚本

MSXML2.XMLHTTP将数据发送到PHP脚本,php,mysql,vba,outlook,Php,Mysql,Vba,Outlook,我一直在研究一个选项,将从Outlook消息中的附加文件读取的数据直接发送到PHP脚本,然后将日期插入一个漂亮的MySQL数据库。 文件的提取和数据的分割都可以,但这里有一个技巧 我在网上找到了杰里米·斯莱德写的一篇不错的帖子,他成功地将一些数据发送给了cgi scipt,一切都很好 所以,尽管我认为自己很聪明,但我认为我可以将其重新编写为处理PHP脚本。 但后来工程停止了 我已经将代码缩短为下面的代码片段 Sub TestURL() Set xhr = CreateObject("M

我一直在研究一个选项,将从Outlook消息中的附加文件读取的数据直接发送到PHP脚本,然后将日期插入一个漂亮的MySQL数据库。 文件的提取和数据的分割都可以,但这里有一个技巧

我在网上找到了杰里米·斯莱德写的一篇不错的帖子,他成功地将一些数据发送给了cgi scipt,一切都很好

所以,尽管我认为自己很聪明,但我认为我可以将其重新编写为处理PHP脚本。 但后来工程停止了

我已经将代码缩短为下面的代码片段

Sub TestURL()

    Set xhr = CreateObject("MSXML2.XMLHTTP")
    URL = "http://somedomain.com/php/test.php"

    data = "someVariable=Test"

    With xhr

        .Open "POST", URL, False
        .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
        .Send data

    End With


End Sub
理论上,这应该在给定的URL上打开一个MSXML2.XMLHTTP请求,并向脚本发送任何数据

有趣的是,调用了脚本,但没有传递数据

我已经尝试为[someVariable]元素将PHP脚本设置为$\u GET和$\u POST,但是在这两个元素上都没有响应? 当我将PHP设置为$_GET时,我将VBA MSXML2.XMLHTTP对象与“GET”匹配,反之亦然

我已尝试将'data'变量作为参数传递给'function'。通过将其包含在括号中发送 i、 e

但这也不行

我有点不知所措,因为调用了脚本,一条数据线被添加到了表中,但没有实际传输“已发送”的数据

我尝试将数据字符串连接到传递给HTTP对象的URL,实际上是将“GET”URL传递给HTTP对象。 i、 e

但是没有用…:-(

如果我直接从浏览器传递数据,php脚本本身工作正常 i、 e

正确添加数据并读取变量

能有更多开明的灵魂指引我走向正确的方向吗

20141016**********更新**********

好的,当深入研究我发现的东西时,还有一个选项可以将XmlHttp对象称为“Microsoft.XmlHttp”

有趣的是,当这样设置对象时, i、 e

代码工作,数据被添加到表中,.responseText是一条成功消息

但是,如果我返回到原始代码,我会收到一条PHP错误消息,告诉我PHP语法中有错误??这意味着正在发送的实际“数据”在使用“MSXML2.XMLHTTP”和使用“Microsoft.XMLHTTP”时有所不同

我曾试图从互联网上找出两者之间的差异,但却找不到任何能让我充分理解这一主题的帖子

尽管我的代码现在可以工作了,但我仍然有一个令人困扰的问题,那就是不理解两者之间的区别,我希望有人能给我回复:-)因为我现在有一个可以工作的代码,但不理解它为什么工作…:-) 或者Mroe不理解为什么“MSXML2”选项不起作用


非常感谢

亲切的问候


Martijn

这不完全是一个答案,更像是一个评论,因为我没有足够的声誉来评论

可以使用提供请求和响应详细信息的。我在我的系统中使用MSXML2.XMLHTTP和Mirosoft.XMLHTTP对象检查了与您相同的代码,发现请求之间没有差异。它们都将包含
someVariable=Test的POST请求正文传递到URL
http://somedomain.com/php/test.php

以下是两种情况下的原始POST请求:

POST http://somedomain.com/php/test.php HTTP/1.1
Accept: */*
Accept-Language: en-us
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/5.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E; MS-RTC LM 8)
Host: somedomain.com
Content-Length: 17
Proxy-Connection: Keep-Alive
Pragma: no-cache

someVariable=Test
以及提供的示例URL的响应:

HTTP/1.1 405 Method Not Allowed
Server: nginx/1.7.6
Date: Thu, 08 Jan 2015 15:23:58 GMT
Content-Type: text/html
via: HTTP/1.1 proxy226
Connection: close

<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx/1.7.6</center>
</body>
</html>
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
HTTP/1.1405方法不允许
服务器:nginx/1.7.6
日期:2015年1月8日星期四15:23:58 GMT
内容类型:text/html
via:HTTP/1.1 proxy226
连接:关闭
405不允许
405不允许

nginx/1.7.6
这里的一个问题是,所讨论的web服务器是否期望通过标头(用户代理、引用、cookie等)或作为请求主体的一部分(可能是作为web表单一部分的其他输入元素)传递更多数据

   http://somedomain.com/php/test.php?someVariable=Test 
    Set xhr = CreateObject("Microsoft.XMLHTTP")
POST http://somedomain.com/php/test.php HTTP/1.1
Accept: */*
Accept-Language: en-us
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/5.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E; MS-RTC LM 8)
Host: somedomain.com
Content-Length: 17
Proxy-Connection: Keep-Alive
Pragma: no-cache

someVariable=Test
HTTP/1.1 405 Method Not Allowed
Server: nginx/1.7.6
Date: Thu, 08 Jan 2015 15:23:58 GMT
Content-Type: text/html
via: HTTP/1.1 proxy226
Connection: close

<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx/1.7.6</center>
</body>
</html>
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->