Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using POST with MSINET Control to comm with ASP

Status
Not open for further replies.

AstroPower

Programmer
May 8, 2005
8
EG
How is it possible to invoke POST method with MSINET.OCX
control in a Visual Basic application?

We tried to use Inet.Execute method in this way:
Inet.Execute myURL,"POST","param1=value1&param2=value2"

but ASP page doesn't retrieve any parameters. It seems that the ASP gets empty inputs
Have any ideas?
 
In HTTP, the GET command uses parameters in the URL querystring but POST sends parameters inside the Request header.

Change the method to GET and then in your ASP use:
v1 = Request.QueryString(param1)
v2 = Request.QueryString(param2)

Also, if you are willing to sacrifice speed for compatibility, you could also do this:
v1 = Request(param1)
v2 = Request(param2)

That latter syntax will find parameters passed with both GET and POST but is less efficient.
 
Thanks for reply
What I'm doing is communicating an ASP page in the net from the Vbasic project to do something like activating the software,
1- the exe posts a serial no. and email for example, with the syntax:
Inet1.Execute strUrl, "POST ", strFormData, "Content-Type: application/x-www-form-urlencoded"

2- The ASP checks if the serial is correct and replies with another calculated key:
<% if request.form("XXX")="yyy" then response.write("KEY")%>

3- the exe receive that key from the ASP to do activation to the exe to convert from demo to ful mode exe
data = Inet1.GetChunk(32000, 0)

do you mean I have to replace the post by the get in the first step?

 
No that should work also... In my opinion GET is easier to do than POST, mostly because you can paste it into the browser address to test the ASP side of the application.

I made a little VB project... it has a command button and an inet control on a form. The code looks like this:
Code:
Private Sub Command1_Click()
    Dim sURL As String
    Dim sData As String
    
    sURL = "127.0.0.1/test.asp"
    sData = "foo=bar"
    Inet1.Execute sURL, "POST ", sData, "Content-Type: application/x-[URL unfurl="true"]www-form-urlencoded"[/URL]
End Sub

Private Sub Inet1_StateChanged(ByVal State As Integer)
    If State = icResponseCompleted Then
        Debug.Print Inet1.GetChunk(32000)
    End If
End Sub

And then I made test.asp like this:
Code:
<html>
  <head>
    <title>Test Page</title>
  </head>
  <body>
    This is a test page.
    <br />
    <br />
<%
Dim key
Response.Write "Request.Form contains: <br />" & vbCrLF
For Each Key In Request.Form
  Response.Write key & " = " & Request.Form(key) & "<BR>" & vbCrLf
Next
Response.Write "<br />" & vbCrLf
Response.Write "Request.QueryString contains: <br />" & vbCrLF
For Each Key In Request.QueryString 
  Response.Write key & " = " & Request.QueryString(key) & "<BR>" & vbCrLf
Next
Response.Write "<br />" & vbCrLf
Response.Write "Request.ServerVariables contains: <br />" & vbCrLF
For Each key in Request.ServerVariables
  Response.Write key & " = " & Request.ServerVariables(key) & "<BR>" & vbCrLf  
Next
%>
  </body>
</html>

With test.asp on my local instance of IIS web server, I ran the VB app, clicked the button, and got the following in my debug window:
<html>
<head>
<title>Test Page</title>
</head>
<body>
This is a test page.
<br />
<br />
Request.Form contains: <br />
foo = bar<BR>
<br />
Request.QueryString contains: <br />
<br />
Request.ServerVariables contains: <br />
ALL_HTTP = HTTP_ACCEPT:image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
HTTP_HOST:127.0.0.1
HTTP_USER_AGENT:Microsoft URL Control - 6.01.9782
HTTP_COOKIE:ASPSESSIONIDASRQTQDD=DICDMAFANOEEEOLNNNDPFPCM
HTTP_CONTENT_LENGTH:7
HTTP_CONTENT_TYPE:application/x-HTTP_CACHE_CONTROL:no-cache
<BR>
ALL_RAW = Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
Host: 127.0.0.1
User-Agent: Microsoft URL Control - 6.01.9782
Cookie: ASPSESSIONIDASRQTQDD=DICDMAFANOEEEOLNNNDPFPCM
Content-Length: 7
Content-Type: application/x-Cache-Control: no-cache
<BR>
APPL_MD_PATH = /LM/W3SVC/1/ROOT<BR>
APPL_PHYSICAL_PATH = c:\inetpub\AUTH_PASSWORD = <BR>
AUTH_TYPE = <BR>
AUTH_USER = <BR>
CERT_COOKIE = <BR>
CERT_FLAGS = <BR>
CERT_ISSUER = <BR>
CERT_KEYSIZE = <BR>
CERT_SECRETKEYSIZE = <BR>
CERT_SERIALNUMBER = <BR>
CERT_SERVER_ISSUER = <BR>
CERT_SERVER_SUBJECT = <BR>
CERT_SUBJECT = <BR>
CONTENT_LENGTH = 7<BR>
CONTENT_TYPE = application/x-GATEWAY_INTERFACE = CGI/1.1<BR>
HTTPS = off<BR>
HTTPS_KEYSIZE = <BR>
HTTPS_SECRETKEYSIZE = <BR>
HTTPS_SERVER_ISSUER = <BR>
HTTPS_SERVER_SUBJECT = <BR>
INSTANCE_ID = 1<BR>
INSTANCE_META_PATH = /LM/W3SVC/1<BR>
LOCAL_ADDR = 127.0.0.1<BR>
LOGON_USER = <BR>
PATH_INFO = /test.asp<BR>
PATH_TRANSLATED = c:\inetpub\QUERY_STRING = <BR>
REMOTE_ADDR = 127.0.0.1<BR>
REMOTE_HOST = 127.0.0.1<BR>
REMOTE_USER = <BR>
REQUEST_METHOD = POST<BR>
SCRIPT_NAME = /test.asp<BR>
SERVER_NAME = 127.0.0.1<BR>
SERVER_PORT = 80<BR>
SERVER_PORT_SECURE = 0<BR>
SERVER_PROTOCOL = HTTP/1.1<BR>
SERVER_SOFTWARE = Microsoft-IIS/5.0<BR>
URL = /test.asp<BR>
HTTP_ACCEPT = image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*<BR>
HTTP_HOST = 127.0.0.1<BR>
HTTP_USER_AGENT = Microsoft URL Control - 6.01.9782<BR>
HTTP_COOKIE = ASPSESSIONIDASRQTQDD=DICDMAFANOEEEOLNNNDPFPCM<BR>
HTTP_CONTENT_LENGTH = 7<BR>
HTTP_CONTENT_TYPE = application/x-HTTP_CACHE_CONTROL = no-cache<BR>

</body>
</html>

... so you see it worked just fine.
 
Sheco
Thank u for pointing me to usefull example. Since
i am working on php . Could u tell me how i can pass
a value that has name :mp3link and value data from texbox and also how to output back the http response back to a richtexbox.in the example shown in the page it only passes one data without name(sData = "foo=bar") :Thanks

This is the html code for the script.php
Code:
<form method=post action="script.php">
MP3 Link: <input type="text" name="mp3link" size="35">&nbsp;
<input type="submit" value="Check it!"><br><br>

If i use this on web after typeing a url in textbox and press submit it process the url and send me back with output that lookes like this :
Code:
Link: [URL unfurl="true"]http://ww.site.com/lifesong.mp3[/URL] 
Song: life song
Artist: andy
Album: power 
Year: 
Comment: 
Track: 1
Genre: Other

so i want to get same type of output after posting in my form in a richtextbox but your codes does not do that!! I be happy if u help me here.Thanks
Code:
[URL unfurl="true"]http://localhost/script.php[/URL]

method : post

Name : mp3link

value : Text3

HTTP Response back to richtexbox
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top