Link to home
Start Free TrialLog in
Avatar of seekin
seekin

asked on

VB6 POST using WinHttp.WinHttpRequest

I need to POST a command to a web site. The command is in the form Dial:12345678. I am attempting this using the WinHttp.WinHttpRequest object but not having much joy. Does any body have any ideas.

Thanks,

Mike
Avatar of jamesrh
jamesrh
Flag of United States of America image

Do you have the specs for what you are trying to do/ the website or address you are trying to work with.  The way you are asking the question, it dosen't totally make sense.
Avatar of seekin
seekin

ASKER

Thanks for your response. The 'web site' is in fact a VOIP phone which has a url built into it which takes commands to operate the phone from a remote request. In this case I need to dial out from a PC based application written in VB6

Cheers,

Mike
I figured that was the case.  What device are you trying to hit?
I think I can probably help you, but I need whatever you have in the way of info or specs.  If I knew what exactly the http request was supposed to look like I could tell you how to get it over there.  I tried finding something useful on my own but everything simply mentions the possiblity of remote management, I don't seem to find anything with any useful data about the process.  
Avatar of seekin

ASKER

Thanks, yes there seem to be two ways to handle this. One is by remote management of the 'switch' which is going to be a sledge hammer to crack a nut plus some. The other way is by 'POST'ing commands directly to the phone. The information that I have is as follows "If you want to dial a number from the phone just use the following:
Dial:xxxx
execute it to the phone by using http://phone ip address/CGI/Execute (case sensitive)
You need to post it.

Cheers
Mike
You can try to use this from what you have described. However it's unclear like previous post have mentioned if you need to add any additional information into the header before you make the post.

'// Use like this
Option Explicit

Private Sub Command1_Click()
 
  '// TODO://
  Call SimplePost("http://phoneipaddress/CGI/Execute", "Dial:12345678")

End Sub
Option Explicit
 
Private Const INTERNET_SERVICE_HTTP = 3
Private Const INTERNET_FLAG_KEEP_CONNECTION = &H400000
 
Private Declare Function InternetOpenA Lib "wininet" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetConnectA Lib "wininet" (ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Long, ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lcontext As Long) As Long
Private Declare Function HttpOpenRequestA Lib "wininet" (ByVal hConnect As Long, ByVal lpszVerb As String, ByVal lpszObjectName As String, ByVal lpszVersion As String, ByVal lpszReferer As String, ByVal lplpszAcceptTypes As String, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
Private Declare Function HttpSendRequestA Lib "wininet" (ByVal hRequest As Long, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal lpOptional As Long, ByVal dwOptionalLength As Long) As Long
Private Declare Function InternetCloseHandle Lib "wininet" (ByVal hInternet As Long) As Long
 
Public Sub SimplePost(ByVal szUrl As String, ByVal szObject As String)
  
  Dim hOpen As Long
  Dim hConn As Long
  Dim hRequest As Long
  
  hOpen = InternetOpenA("Inet/Cisco7945G", 0, vbNullString, vbNullString, 0)
  
  hConn = InternetConnectA(hOpen, szUrl, 80, vbNullString, vbNullString, INTERNET_SERVICE_HTTP, 0, 0)
  
  hRequest = HttpOpenRequestA(hConn, "POST", szObject, vbNullString, vbNullString, vbNullString, INTERNET_FLAG_KEEP_CONNECTION, 0)
 
  Call HttpSendRequestA(hRequest, vbNullString, 0, 0, 0)
  
  InternetCloseHandle hConn
  InternetCloseHandle hOpen
  InternetCloseHandle hRequest
  
End Sub

Open in new window

Avatar of seekin

ASKER

OK thanks for that. I have no information about the header.  I  don't actually have access to the phone system so have constructed an asp page which saves the request.form data to a file so that I can check that the POSTed data has arrived. It's 01:46 here so I am going to have to leave it now but I will have a play with that tomorrow.

Thanks again,

Mike
Hi Mike,
I want to mention you might have to request without the http:// protocal.

Call SimplePost("phoneipaddress/CGI/Execute", "Dial:12345678")

Hopefully this works for you I'll keep an eye out for your response/results when you get the chance. :)
ASKER CERTIFIED SOLUTION
Avatar of seekin
seekin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Cool man you got it working :)

I think if we have updated my code with the header part "Content-Type", "application/x-www-form-urlencoded" it would have worked for you. This is okay you should request a refund because you answered your own question :)
Avatar of seekin

ASKER

Cheers will do, thanks again.

Mike