I have found a script online which allows me to post to a http page via powershell. The problem i have is that although it shows no errors and seems to get responses back ok, i never actually see any posted data. Anyone got any ideas?
Without knowing what the Web page is doing on the other end, it’s impossible to say. It could be looking for a cookie you haven’t passed, it might not be intended to return any data, it might be checking referrer strings, it could be a million things.
Dim fso
Dim tst
Set fso = Server.CreateObject(“Scripting.FileSystemObject”)
Set tst = fso.OpenTextFile(“c:\inetpub\wwwroot\text\reading.txt”, 2, true)
tst.writeline Request.Form(“mac”)
tst.writeline Request.Form(“tp”)
tst.close
Set tst = Nothing
Set fso = Nothing
%>
This is a test of my <%=tp%> variable
<form name=“input” action=“test.asp” method=“post”>
Username: <input type=“text” name=“mac”>
<input type=“text” name=“tp”>
<input type=“submit” value=“Submit”>
</form>
Im posting the following to the form, but no matter what i put in there, it does not show up in the form
So, when you do a POST, the form fields go into the HTTP request, but they have to be formatted in a specific way. The server decodes that and, in the case of ASP, give you the Request object. My guess is that the information isn’t going into the right format or spot, so the server doesn’t “see” it. Manually constructing a set of POST headers is a little outside my expertise, though.
So, you’re not technically “posting the following to the form.” You’re posting it to the server. The server doesn’t “insert the values into the form fields;” your actual HTML form tags aren’t being used by your PowerShell code.
This would be a lot easier with a GET. You just call your Web page with URL parameters: mywebpage.asp?nic=xxx&mac=abc123. Then you don’t have to construct POST headers and whatnot. But it still doesn’t “fill in the form fields;” it’s just sending the values AS IF the form had been manually filled out.
(Invoke-WebRequest is in PowerShell v3 and later; it’s a lot easier than using the WebRequest .NET class directly, but you’re welcome to use the class instead of the cmdlet if you prefer.)
GET just involves putting your data into the URL, as I’ve shown here, rather than building a set of POST headers.
I guess the problem that im trying to get around is that i was hoping to post to ssl thereby encrypting the data. If it’s in the URL string then the thats not going to work so well.
This does however kind of of prove that the process is achievable. All be it without the desired end result