Re: Problems sending $_POST vairable to an ASP page

From: Date: Fri, 29 Aug 2008 07:38:27 +0000
Subject: Re: Problems sending $_POST vairable to an ASP page
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-278937@lists.php.net to get a copy of this message
On 28 Aug 2008, at 22:17, shaun thornburgh wrote:
Hi guys, I need to send post variables to an ASP page. I have the following code which isn't producing any errors but isn't working either: foreach($_POST['newsletter-group'] as $key => $value){ $_POST['addressbookid'] = $value; $out = "POST /signup.ashx"; $fp = fsockopen("dmtrk.net", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { fputs($fp, $out . "\r\n"); } fclose($fp); } Can anyone tell me what I am doing wrong please?
<?php $result = false; // I can't see in your example where you're building the POST data, but here's an example $postdata = 'var='.urlencode($value); $fp = fsockopen('dmtrk.net', 80, $errno, $errstr, 30); if (!$fp) { $result = 'Connection failed: ['.$errno.'] '.$errstr; } else { fwrite($fp, "POST /signup.ashx HTTP/1.1\n"); fwrite($fp, "Connection: close\n"); fwrite($fp, "Host: dmtrk.net\n"); fwrite($fp, "Content-Length: ".strlen($postdata)."\n"); fwrite($fp, "Content-Type: application/x-www-form-urlencoded\n"); fwrite($fp, "\n".$postdata."\n"); // Get the status $response = fgets($fp); $result = (strpos($response, ' 200 ') !== false); // Read the rest of the response while (!feof($fp)) { $response .= fgets($fp); } @fclose($fp); if (!$result) $result = $response; } // At this point $result will either be === true or it will contain an error message // Please don't ask a question again without doing a reasonable amount of research first. In this case that would be the HTTP spec and the PHP socket function documentation. This was not difficult! ?> -Stut -- http://stut.net

« previous php.general (#278937) next »