Jump to content

Recommended Posts

Posted (edited)

I am trying to write a script to sent POST data to our Alpha Page provider so I can send a page in a SQL script.  I have written the script below which works perfectly on my Windows XP workstation.  When I try to run it on my server (Windows Server 2008 RS SP1) it doesn't work at all.  Here's my script:

If $CmdLine[0] < 2 Then
    MsgBox(0,"MISSING PARAMETERS","Must supply command parameters Pager Number and Message to send." & @CRLF & "Pager should NOT include dashes, and Message MUST be enclosed in quotes" & @CRLF & @CRLF & "Example:" & @CRLF & "AutoPage.exe 8885551234 ""This is a test message""",15)
    Exit ; No parameters, nothing to do!
EndIf

$pager = $CmdLine[1] ; The first parameter - PAGER NUMBER
$msg = $CmdLine[2] ; The second parameter - MSG TO BE SENT
$msg = StringReplace($msg, " ", "+")

; The final POST data to be sent via HTTP
$sPD = 'pager_num=' & $pager & '&message=' & $msg

; Creating the object
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", "http://www.propage.net/cgi-bin/propage/pager_test.pl", False)
$oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")

; Performing the Request
$oHTTP.Send($sPD)

; Download the body response if any, and get the server status response code.
$oReceived = $oHTTP.ResponseText
$oStatusCode = $oHTTP.Status

; Saves the body response regardless of the Response code
$file = FileOpen("Received.html", 2) ; The value of 2 overwrites the file if it already exists
FileWrite($file, $oReceived)
FileClose($file)

Exit

The HTTP response from my WORKING workstation looks like this:

<html>
<head>
<title>Pager Service</title>
</head>
<body bgcolor="white" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">


<table width="100%" BORDER=0 CELLPADDING=0 CELLSPACING=0>
<tr><td valign="top">
<br><font face="arial,helvetica,verdana" color="#1d0975">
<blockquote>
  <a href="http://www.propage.net" target="window"><img src="http://www.propage.net/imgs/netbanner.gif" align="right" border="0"></a>
  <B>LAST MESSAGE STATUS:</B>
  <br><br>

  Successfully sent to 888xxxxxxx <br>
<br><br><br>
  If this is the correct number or user-name for the intended subscriber, the message will normally be received within 10 to 15 seconds.<br><br>
  If there was an error and the message was not sent, please click the <b>BACK</B> button on the browser and try again.
</P>

</blockquote></font>
</td>
    <TD valign="top"></td>
    <TD valign="top"></TD>

<TR>
    <TD colspan="3"><font face="arial,helvetica,verdana" color="#1d0975">
<hr with="100%">
<br>
<blockquote>
<br>
<OL>
</OL>
</blockquote></font>
</TD></TR>
</table>
 
</body>
</html>

While the Response code from the server looks like this:

<html>
<head>
<title>cgi-lib.pl: Unknown Content-type: application/x-www-form-urlencoded; Charset=UTF-8
</title>
</head>
<body>
<h1>cgi-lib.pl: Unknown Content-type: application/x-www-form-urlencoded; Charset=UTF-8
</h1>

Does anyone have any suggestions on what could be happening here?

Edited by MuffinMan
Posted

OK, I tried this on serveral different servers and it ran fine EXCEPT on Windows Server 2008 machines.  I did some research and found that there seems to be some sort of issue with WinHTTP on Server 2008.  I changed my object to:

$oHTTP = ObjCreate("MSXML2.XMLHTTP")

Which uses WinINet instead on WinHTTP.  My code now seems to be working on Server 2008 and the rest of the servers / workstations.  Still very interested if anyone else has anything to add, but bottom line is the code works now.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...