[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Post Form Data With Inet Control

Posted on 2006-11-22
Medium Priority
Last Modified: 2010-08-05
This is funny.  I just googled how to do this and found 10 message boards with the question, but none with the answer!  LOL  

I need to post form data to a URL via an Internet Transfer Control (Inet).  I can see from Intellisense that I need to change the Inet.Execute statement, but I cannot figure out what I am supposed to fill in for the operation, input data,. and input headers (I think it says it wants hdrs, or headers).   This is the general format:
'***Inet1.Execute URL, <operation>, <input data>, <input hdrs>
'Form data fields.  I am not sure if these are formatted correctly.  Seems like I should need the form name...but I don't know what I am doing here.
PostData = "imgsize=320;opt=-l;lat=22.125;ns=North;lon=99.625;ew=West;alt=148024950;img=learth.evif"
'This execute statement bombs, saying it "cannot coerce type."
Inet1.Execute "http://www.fourmilab.ch/cgi-bin/Earth?, PostForm, PostData

Unfortunately, I do not have a good VB reference, so I could not look this up.  I feel like an idiot, but really appreciate any help people can send along.

Thank you.
Question by:Danimal
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
LVL 16

Accepted Solution

JohnBPrice earned 300 total points
ID: 17995239
Hi Danimal,

There are basically two ways to post data, one is to use HTTP POST operations, and one is to use HTTP GET.  With POST, the data is posted as individual controls on a web form, with GET, the data is passed in the URL itself.  Your code above is trying to do a POST.  POST has always been dicey for me, but if you look at the code I posted in your earlier question, http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_22057064.html, (thanks for the points BTW), you'll see I was actually doing a GET (which is the default if you don't explicitly specify "POST", thus, the data is actually appended to the URL after the "?", as in

Inet1.Execute "http://www.fourmilab.ch/cgi-bin/Earth?" & PostData

Sorry for the confusion, I should not have named the variable "PostData", perhaps "URLParams" would have less misleading.  I actually tried POST first, but couldn't figure it out, and I noticed some of the samples did a GET, so GET was easier.

This particular site appears to accept both POST and GET, and since GET is simpler, I used GET.  Also note that your code has a couple issues if you really want to do a post, first, your do not want the "?" in the url, because POST doesn't use it.  Second, you must use the word "POST" as the second parameter, e.g. the <operation>, which I believe you missed in your actual code.

Author Comment

ID: 17995281
IThank you John.  I understand what you are saying.  

If you look at the value of PostData in the answer your provided, there are semicolons.  Taking them out seems to have fixed this.

I need to work with this a little


Author Comment

ID: 17995668
removing the semi colons solved the problem.  

I have a new problem though.  The download of the picture does not always work.  I am not changing anything.  Just running, deleting the files downloaded, running again..over and over.  Most of the time it works, but not always.  Any thoughts on that?  When it doesn't work, the picture .jpg file downloads as 0 bytes.  I am saving the URL of the photos.  The URLs are good, but the picture file building just doesn't happen everytime.  It seems as if the server is rejecting the URL, but like I said, I save and test those... so I don't know.
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

LVL 16

Expert Comment

ID: 17995996
ooops, as I said "I actually tried POST first, but couldn't figure it out", I must have cut and paste incorrectly.
LVL 16

Expert Comment

ID: 17996044
when it fails, take a look at the headers you receive, they might give you a clue as to why it failed.  You can get the headers using Inet1.GetHeader, which with no parameters, returns all the headers, including the HTTP success/error code.

Also, you can check if you get no data before saving, just check ubound(Image) where Image is the byte array you filled with GetChunk.

Author Comment

ID: 17996534
ok..taking a break now... but I will see what is up.

thax again..and have a happy thanksgiving.

Author Comment

ID: 18001195
John, after executing Inet1.GetHeader, how do you usually examine the results coming back.  I really don't have a lot of experience with VB, so I am looking for some little tricks.  I assume there are a lot of options...like using the debugger, or writing the results to a text file... can you offer a few off the top of your head tips?

Ditto for the unbound(Image)... and the GetChunk command.  

I think I can work this through.  I am looking for tips I might pick up if i were looking over your shoulder when you were programming.

If I don't talk to you sooner, Happy Thanksgiving.
LVL 16

Expert Comment

ID: 18019311
Yep, a lot of options.  I think perhaps the best for this site is to check the http return code in the header.  If it is HTTP OK, then you can assume you got the image.  Note once you get a look at all the headers with GetHEader, you can fetch only the one you want with GetHeader("HeaderNAme").  I forget exactly what the return code is named, but you will see it in GetHeader.

If you want to see the value of a property, you can just hover over it and VB will show you the value (but not getHeader, it is a method not a property).  If I just want to see GetHeader once in debug mode, I'll go to the immediate command window and do "?inet1.GetHeader".  The "?" is shorthand for "Print".  If I want to monitor some value, I'll add a watch.  Highlight the variable or expression, such as "Inet1.GetHeader", right click and "add watch".  You might want to simply choose "Inet1", and the watch will show you all the variables (but not the method calls like GetHeader).  The watched values update automatically as you step through the code.

You can do the same for ubound(Image), however GetChunk istelf is dicier because it is a byte array, not a string.  Also, you can not call it repeatedly and get the same results (it's pulls the chunk out after you get it).  So if you want to see the value, you have to look at the resulting Image byte array, not that it would do you much good since it is a JPG binary data.

If it is going to be an unattended process, and I want to track how it works, I'll write out bits to a log file.  Here is the core stuff from my logging routine, so that I can simply call

LogMessage "blah blah blah " & inet1.Getheader

or whatever you want to include in the logfile

Public Sub LogMessage(msg As String, Optional SuppressTimeStamp As Boolean)
    'write a new message to the current log file, create a new log file is one is not currently open
    If LogFile Is Nothing Then 'logfile not created yet
        Set LogFile = fs.OpenTextFile(App.Path & "\logfile.txt", ForWriting, True)
        LogFile.WriteLine "Logfile  created " & Now
    End If
    If msg <> "" Then
        If SuppressTimeStamp Then
            LogFile.WriteLine (msg)
            LogFile.WriteLine (Format(Now(), "Medium Time") & " - " & msg)
        End If
        LogFile.WriteBlankLines 1
    End If
End Sub


Author Comment

ID: 18027083
WOW!  What a great response... I am in awe, and I am not worthy.  Thank you a million times!
Thank you 1
Thank you 2
Thank you 3
Thank you 4
Thank you 5
Thank you 6
Thank you 7
Thank you 8
Thank you 9
Thank you 10
Thank you 11
Thank you 12
Thank you 13
Thank you 14
Thank you 15
Thank you 16
Thank you 17
Thank you 18
Thank you 19
Thank you 20
Thank you 22
Thank you 23
Thank you 24
Thank you 25
Thank you 26
Thank you 27
Thank you 28
Thank you 29
I hope you get the idea.  :-)  I really appreciate the help.  :-)  Thank you.  You are my hero.


Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question