473,773 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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::po st() 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_SUBSCRI PTION>
<COMPANY CORPORATE_MASTE R_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_SUBSCRIPT ION>";

// Send xml data to initiate email alert sign-up.
require_once('H TTP/Client.php');
$c =& new HTTP_Client();
$c->post('$url', $data');
$response = $c->currentRespons e();
//echo $response['body'];
echo "<pre>"; print_r($respon se); 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("M SXML2.xmlhttp")
Set xmlDoc = New DOMDocument26
URL = "http://www.corporate-ir.net/ireye/xmlsub.asp"

xmlDoc.Load "C:\Documen ts and Settings\jdoe\D esktop\alert.xm l"

xmlObj.open "POST", URL, False
xmlObj.send xmlDoc.xml
response = xmlObj.response Text '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 11820


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::po st() 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_SUBSCRI PTION>
<COMPANY CORPORATE_MASTE R_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_SUBSCRIPT ION>";

// Send xml data to initiate email alert sign-up.
require_once('H TTP/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->setRequestHead er('Content-Type', 'application/xml');

--

Martin Honnen
http://JavaScript.FAQT s.com/
Jul 20 '05 #2
"designsimp ly" <sh**********@g mail.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($respo nse);" 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::he ad and
HTTP_Client::se tDefaultHeader( ).
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::he ad (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->setDefaultHead er('Content-Type', 'application/xml');
HTTP_Client::se tDefaultHeader (mixed $name [, string $value = NULL])
http://pear.php.net/manual/en/packag...aultheader.php

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

And this.
$default_header s = array('Content-Type' => 'application/xml');
$c->setDefaultHead er($default_hea ders);

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('H TTP/Client.php');
$c =& new HTTP_Client();
$c->setDefaultHead er('Content-Type', 'application/xml');
$c->post('$url', $data');
$response = $c->currentRespons e();
echo "<pre>"; print_r($respon se); 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->setRequestHead er('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($u rl);
$req->addHeader("Con tent-Type", "text/xml");
$req->addHeader("Con tent-Length", strlen($data));
$req->setMethod(HTTP _REQUEST_METHOD _POST);
$req->addRawPostData ($data, true);
$req->sendRequest( );
echo $req->getResponseBod y();

Jul 20 '05 #6

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

Similar topics

1
8577
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 users etc). I am trying to write a little test app to test the workflow of the servlet application. The problem is I need to keep the same session alive and post via that session.
8
10648
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 Request" was the original error msg now that I reinstalled iislockdown and urscan I get "The parameter is incorrect." If I use the get method with this form it works just fine on everything. I can't say for certain but I think this problem started...
6
2141
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" action="http://www.theirsite.htm"> <input type=hidden name="field1" value="value1"> <input type=hidden name="field2> value="value2> <input type="submit" value="Click Me"> On my web form, I have numerous web controls ( all runat="server"), one of which is a button which...
3
11292
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 to receive files back. I've got the XML file generated and checked over, but I just dont know how to go about the post process. I've got a feeling I'm supposed to create a form in my ASP application with an action which points at the URL I've...
0
1831
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 programs can be successfully compiled. There is no error message shown at running also. But the httpLook confirms that the program doesn't post. -- Here is the HTTP request acquired by the software: ---
0
3885
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 tools like ieHTTPHeaders v1.6, and I perform a normal login (using the normal website), I see that the viewstate is __VIEWSTATE=dDwxMzU4OTE3NTA2Ozs%2BTK88jS63JXN181X3N8zKivua8co%3D&txt_username=xxx&txt_password=xxxxxx&btn_login=Login. When I...
5
10401
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 they need to consume this web service using HTTP. The developer's IDE is Notepad. Yeah, weird I know. How is this done? I guess if I can get it to run ASP, IDE independant, that should make them happy. Any references you can point me to?
3
4930
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 one post for every 10 seconds the client start getting error 403 'forbidden' from the webserver after a short period of time. The webserver is IIS. The choking of the client/server communication when doing high frequency posting is due to that we...
1
2607
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 Page_Load(object sender, System.EventArgs e) {
6
5107
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 how to encode a file on a POST to the same web service. The definition requires a base64binary encoded file, which I have tried. The form is also using a mutlipart/form-data enctype, but I either get a 500 error or 'Request format is invalid'. ...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4012
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.