472,373 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,373 software developers and data experts.

Can I http post xml using php?

I am trying to http post some xml to to a remote server using php. When
I try to submit xml using PEAR's HTTP_Client::post() to the remote
server, I get back the following "Invalid Document Format" error:

Array
(
[code] => 200
[headers] => Array
(
[Connection] => close
[connection] => close
[Server] => Microsoft-IIS/6.0
[server] => Microsoft-IIS/6.0
[X-Powered-By] => ASP.NET
[x-powered-by] => ASP.NET
[Content-Length] => 51
[content-length] => 51
[Content-Type] => text/html
[content-type] => text/html
[Cache-Control] => private, max-age=0
[cache-control] => private, max-age=0
[Date] => Mon, 16 May 2005 13:46:57 GMT
[date] => Mon, 16 May 2005 13:46:57 GMT
)

[body] => Invalid Document Format

Here is my php code:

// Variables
$url = "http://www.corporate-ir.net/ireye/xmlsub.asp";
$data = "<ALERT_SUBSCRIPTION>
<COMPANY CORPORATE_MASTER_ID="{valid id removed}">
<MEMBERS>
<MEMBER>
<EMAIL_ADDRESS>{valid email removed}</EMAIL_ADDRESS>
<ALERTS>
<ALERT SUBSCRIBE="YES">IR-NEWS</ALERT>
<ALERT SUBSCRIBE="YES">IR-EVENT</ALERT>
<ALERT SUBSCRIBE="YES">IR-SEC</ALERT>
<ALERT SUBSCRIBE="YES">IR-RPT</ALERT>
<ALERT SUBSCRIBE="YES">IR-MEDIA</ALERT>
</ALERTS>
</MEMBER>
</MEMBERS>
</COMPANY>
</ALERT_SUBSCRIPTION>";

// Send xml data to initiate email alert sign-up.
require_once('HTTP/Client.php');
$c =& new HTTP_Client();
$c->post('$url', $data');
$response = $c->currentResponse();
//echo $response['body'];
echo "<pre>"; print_r($response); echo "</pre>"; // easier to see full
response

Here is a VB example from the documentation I was given, but I am
trying to do it with php instead.

Dim xmlObj As MSXML2.XMLHTTP
Dim URL As String
Dim response As String
Dim xmlDoc As DOMDocument26

Set xmlObj = CreateObject("MSXML2.xmlhttp")
Set xmlDoc = New DOMDocument26
URL = "http://www.corporate-ir.net/ireye/xmlsub.asp"

xmlDoc.Load "C:\Documents and Settings\jdoe\Desktop\alert.xml"

xmlObj.open "POST", URL, False
xmlObj.send xmlDoc.xml
response = xmlObj.responseText 'view the value of response to see if
the post was successful
MsgBox "Done"

End Sub

Thank you very much for any help with this.

Jul 20 '05 #1
5 11716


designsimply wrote:
I am trying to http post some xml to to a remote server using php. When
I try to submit xml using PEAR's HTTP_Client::post() to the remote
server, I get back the following "Invalid Document Format" error:

Array
(
[code] => 200
[headers] => Array
(
[Connection] => close
[connection] => close
[Server] => Microsoft-IIS/6.0
[server] => Microsoft-IIS/6.0
[X-Powered-By] => ASP.NET
[x-powered-by] => ASP.NET
[Content-Length] => 51
[content-length] => 51
[Content-Type] => text/html
[content-type] => text/html
[Cache-Control] => private, max-age=0
[cache-control] => private, max-age=0
[Date] => Mon, 16 May 2005 13:46:57 GMT
[date] => Mon, 16 May 2005 13:46:57 GMT
)

[body] => Invalid Document Format

Here is my php code:

// Variables
$url = "http://www.corporate-ir.net/ireye/xmlsub.asp";
$data = "<ALERT_SUBSCRIPTION>
<COMPANY CORPORATE_MASTER_ID="{valid id removed}">
<MEMBERS>
<MEMBER>
<EMAIL_ADDRESS>{valid email removed}</EMAIL_ADDRESS>
<ALERTS>
<ALERT SUBSCRIBE="YES">IR-NEWS</ALERT>
<ALERT SUBSCRIBE="YES">IR-EVENT</ALERT>
<ALERT SUBSCRIBE="YES">IR-SEC</ALERT>
<ALERT SUBSCRIBE="YES">IR-RPT</ALERT>
<ALERT SUBSCRIBE="YES">IR-MEDIA</ALERT>
</ALERTS>
</MEMBER>
</MEMBERS>
</COMPANY>
</ALERT_SUBSCRIPTION>";

// Send xml data to initiate email alert sign-up.
require_once('HTTP/Client.php');
$c =& new HTTP_Client();


I don't know the API of HTTP_Client but you should make sure you set the
Content-Type header to application/xml before you post the XML as only
then the server knows it receives XML. Thus you need to find out how you
set a request header with that client and then do e.g.
$x->setRequestHeader('Content-Type', 'application/xml');

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
"designsimply" <sh**********@gmail.com> writes:
Array
(
[code] => 200
[headers] => Array
(
[Connection] => close
[connection] => close


What is the name of this markup language?

(I.e., the language defining this use of
"(", ")", "[", "]", and "=>".)
Jul 20 '05 #3
>Array
(
[code] => 200
[headers] => Array
(
[Connection] => close
[connection] => close


The formatting for the above block of text is how php prints out an
array when you call print_r($array). See
http://us2.php.net/manual/en/function.print-r.php. I called
"print_r($response);" in my code to view how the server I want to post
xml to is handling the request.

Jul 20 '05 #4
Should the content type for an http post of xml be text/xml or
application/xml? Also, I am not sure how to set the header from within
the HTTP_Client PEAR package.

In the PEAR HTTP_Client documentation, I see that there are a couple
functions that might help: HTTP_Client::head and
HTTP_Client::setDefaultHeader().
http://pear.php.net/manual/en/packag...ttp-client.php

The head function looks like a possibility, but the "string $url"
syntax doesn't seem right for sending a content-type header.
HTTP_Client::head (string $url)
http://pear.php.net/manual/en/packag...lient.head.php

I tried this function by putting the following, but I get the same
"Invalid Document Format" error back.
$c->setDefaultHeader('Content-Type', 'application/xml');
HTTP_Client::setDefaultHeader (mixed $name [, string $value = NULL])
http://pear.php.net/manual/en/packag...aultheader.php

I also tried this.
$c->setDefaultHeader('Content-Type', 'application/xml');

And this.
$default_headers = array('Content-Type' => 'application/xml');
$c->setDefaultHeader($default_headers);

Can someone help me with my PEAR HTTP_Client syntax?

Here's my new code block that does not seem to be sending the proper
xml content-type header.

// Send xml data to initiate email alert sign-up.
require_once('HTTP/Client.php');
$c =& new HTTP_Client();
$c->setDefaultHeader('Content-Type', 'application/xml');
$c->post('$url', $data');
$response = $c->currentResponse();
echo "<pre>"; print_r($response); echo "</pre>";
Martin Honnen wrote:

I don't know the API of HTTP_Client but you should make sure you set the Content-Type header to application/xml before you post the XML as only then the server knows it receives XML. Thus you need to find out how you set a request header with that client and then do e.g.
$x->setRequestHeader('Content-Type', 'application/xml');

--

Martin Honnen
http://JavaScript.FAQTs.com/


Jul 20 '05 #5
With Justin Patrin's help (thanks Justin!), I figured out the solution
for how to post an xml structure to a remote server using php. I used
HTTP_Request and not HTTP_Client. Here is what I did:

$req =& new HTTP_Request($url);
$req->addHeader("Content-Type", "text/xml");
$req->addHeader("Content-Length", strlen($data));
$req->setMethod(HTTP_REQUEST_METHOD_POST);
$req->addRawPostData($data, true);
$req->sendRequest();
echo $req->getResponseBody();

Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: SPG | last post by:
Hi, I have a servlet application that I am trying to write a very basic load tester for. There application has several servlets, but all rely on the same session being used (IE: For logged in...
8
by: turnit \(removethis\) | last post by:
I have a login form that uses the post method to carry the information to the next page. The form works just fine in ie6.0, but fails in mozilla and fails in ie5.2 on a mac. "HTTP/1.1 400 Bad...
6
by: Phillip N Rounds | last post by:
I have a webform, from which I have to submit info to another site. Their instructions are to have a html form, with the following as the submit: <form method="post"...
3
by: Paul M | last post by:
Hi Sorry if this is posted in the wrong group but I'm brand new to this area. Basically I've got to post some XML documents to an external server using HTTP web request (POST, not GET) and be able...
0
by: Owen | last post by:
Hello everyone, I am using VS.NET 2003(Trandition Chinese) Edition, and httpLook software for checking http requests. I found a problem that the following programs don't really "POST". These...
0
by: WIWA | last post by:
Hi, I want to login to a password protected website and fetch the content of the page behind. I have based my code on http://weblogs.asp.net/jdennany/archive/2005/04/23/403971.aspx. When I use...
5
by: David Lozzi | last post by:
Howdy, I wrote a web service in .Net for my customer. My customer has another vendor who now has to consume it but they are not using Visual Studio. Most of their pages are jsp, and they said...
3
by: JansenH | last post by:
We have implemented a 'HTTP Post' client in C# that posts Xml documents to a webserver. This is working fine if the post rate is one post for every 20 seconds. But if the post rate is increased to...
1
by: Arfeen | last post by:
Hi All, I need help again ..... I have an asp.net web page which I hit using the "HTTP POST" method. My ASP.NET page is a basic hello world example with the following code: private void...
6
by: Brybot | last post by:
I am trying to allow HTTP POST file uploads to my web service. Currently I have it working perfectly for a SOAP/XML request reading in a byte using MemoryStream/FileStream but I cannot figure out...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.