473,288 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

My code gets a HTTP 400 error when I post to IIS 6 servers but works on IIS 5 servers. ??? Something wrong in the header. ?

<?php

// pullpage function by Nick bouton http://www.nickbouton.com/.

$CustomerID = "IDHERE";
$method = "POST";
$host = "xml.mydata.com";
$usepath = "/xml.asp";

//print all vars in an array
function printa($variable) {
echo '<pre>';
//echo "<b>".strtoupper("$variable").":</b>";
print_r($variable);
echo "</pre>";
}

function pullpage ($method, $host, $usepath, $postdata) {
# open socket to filehandle
$fp = fsockopen( $host, 80, &$errno, &$errstr, 120 );

# user-agent name
$ua = "Mozilla/1.0";

if( !$fp ) {
print "$errstr ($errno)<br>\n";
} else {
if ($method == "GET") {
fputs($fp, "GET $usepath HTTP/1.0\n");
} elseif ($method == "POST") {
fputs( $fp, "POST $usepath HTTP/1.0\n");
}
fputs($fp, "User-Agent: ".$ua."\n");
fputs($fp, "Accept: */*\n");

if($method == "POST") {
$strlength = strlen($postdata);
fputs($fp, "Content-type: text/xml\n");
fputs($fp, "Content-length:
".$strlength."\n\n");
fputs($fp, $postdata."\n");
}

fputs( $fp, "\n");
$output = "";

# while content exists, keep retrieving document in 1K
chunks
while (!feof($fp)) {
$output .= fgets( $fp, 1024 );
}

fclose($fp);
}
return $output;
}

//define all vars
$xml_array["Latitude"]="";
$xml_array["Longitude"]="";
$xml_array["ParsedAddressRange"]="";
$xml_array["ParsedPreDirection"]="";
$xml_array["ParsedStreetName"]="";
$xml_array["ParsedSuffix"]="";
$xml_array["ParsedPostDirection"]="";
$xml_array["ParsedSuiteName"]="";
$xml_array["ParsedSuiteRange"]="";
$xml_array["ParsedGarbage"]="";
$xml_array["Company"]="";
$xml_array["Address"]="";
$xml_array["Address2"]="";
$xml_array["Suite"]="";
$xml_array["City"]="";
$xml_array["CityAbbreviation"]="";
$xml_array["State"]="";
$xml_array["Zip"]="";
$xml_array["Plus4"]="";
$xml_array["AreaCodeOfZip"]="";
$xml_array["CarrierRoute"]="";
$xml_array["DeliveryPointCode"]="";
$xml_array["DeliveryPointCheckDigit"]="";
$xml_array["CountyFips"]="";
$xml_array["CountyName"]="";
$xml_array["TimeZone"]="";
$xml_array["TimeZoneCode"]="";
$xml_array["AddressErrorCode"]="";
$xml_array["AddressErrorString"]="";
$xml_array["Msa"]="";
$xml_array["Pmsa"]="";
$xml_array["AddressTypeCode"]="";
$xml_array["AddressTypeString"]="";
$xml_array["Urbanization"]="";
$xml_array["CongressionalDistrict"]="";
$xml_array["PrivateMailBox"]="";
$xml_array["Lacs"]="";
$xml_array["AddressStatusCode"]="";
$xml_array["AddressDatabaseDate"]="";

//set fields passed from form
foreach ($xml_array as $key => $value) {
if(isset($_POST[$key])) { $xml_array[$key]=$_POST[$key]; }
}

//check for custom_xml and override
if (isset($_POST["custom_xml"])) { if(strlen($_POST["custom_xml"])) {
$custom_xml = $_POST["custom_xml"]; } }

// create first part of xml post data
$postdata = "<?xml version=\"1.0\" ?><RecordSet><CustomerID>".
$CustomerID ."</CustomerID><Record>";

//create middle record data of xml post
while (list($key, $value) = each (${"xml_array"})) {
$postdata .= "<". $key.">" .$value."</".$key .">";
$output_array[$key] = "";
}

// append last part of xml post data
$postdata .= "</Record></RecordSet>";

// if custom xml disregard above and use custom xml instead
// also, you can comment out the form and post directly to this php
script
// setting the posted xml variable name to custom_xml

if(isset($custom_xml)) {
$postdata = "<?xml version=\"1.0\" ?><RecordSet><CustomerID>".
$CustomerID ."</CustomerID>". $custom_xml . "</RecordSet>";
}

//do the HTTP POST
$return_content = pullpage( "POST", $host, $usepath , $postdata);
$server_response = $return_content;

//create loop and extract single record for multiple record return

while (ereg('<Record>',$return_content)) {
if(is_array($output_array)) { reset($output_array); }
$start = "<Record>";
$end = "</Record>";
$startpos = strpos($return_content, $start);
$endpos = strpos($return_content, $end) + strlen($end);
$record_content = trim(substr($return_content, $startpos,
$endpos-$startpos));

//remove record content from xml output
$return_content = trim(substr($return_content, $startpos +
strlen($record_content), strlen($return_content)));

if(is_array($output_array)) {
while (list($key, $value) = each (${"output_array"}))
{
$start ="<". $key.">";
$end = "</".$key .">";
$startpos = strpos($record_content, $start) +
strlen($start);
$endpos = strpos($record_content, $end);
$output_array[$key] =
trim(substr($record_content, $startpos, $endpos-$startpos));
if (!strpos($record_content, $start)){
$output_array[$key]=""; }
}
}
}

// note - there is no error checking of the input xml and not a fancy
xml parser or anything so that this will work with
// most php versions
include('mydata_form.php');

?>
Jul 17 '05 #1
0 2416

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

Similar topics

3
by: josh dismukes | last post by:
/// here is the code i'm getting a parse error on the last line of the code which /// is </html> any help will be much appreciated. <?php session_start ();
10
by: Spam Bill Gates | last post by:
I am using linux, php and trying to do some ssl code. I want to send some identifier that connects my database to the client browser. I was looking into a secure cookie. I only want the page...
242
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any...
67
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. ...
15
by: Bryan | last post by:
I have a multi-threaded C# console application that uses WMI (System.Management namespace) to make RPC calls to several servers (600+ ) and returns ScheduledJobs. The section of my code that...
10
by: Don Munroe | last post by:
This one has me stumped. I have three web applications running on two different servers. The first that works fine is hosted by a .Net hosting company. Everyone that uses it has no problems...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
27
by: Dave | last post by:
I'm having a hard time tying to build gcc 4.3.1 on Solaris using the GNU compilers. I then decided to try to use Sun's compiler. The Sun Studio 12 compiler reports the following code, which is in...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

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.