Solved

Post Form Data With Inet Control

Posted on 2006-11-22
9
616 Views
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  


PROBLEM
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.
0
Comment
Question by:Danimal
  • 5
  • 4
9 Comments
 
LVL 16

Accepted Solution

by:
JohnBPrice earned 75 total points
Comment Utility
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.
0
 
LVL 1

Author Comment

by:Danimal
Comment Utility
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

"imgsize=320&;opt=-l&;lat=22.125&;ns=North&;lon=99.625&;ew=West&;alt=148024950&;img=learth.evif"
0
 
LVL 1

Author Comment

by:Danimal
Comment Utility
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.
0
 
LVL 16

Expert Comment

by:JohnBPrice
Comment Utility
ooops, as I said "I actually tried POST first, but couldn't figure it out", I must have cut and paste incorrectly.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 16

Expert Comment

by:JohnBPrice
Comment Utility
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.
0
 
LVL 1

Author Comment

by:Danimal
Comment Utility
ok..taking a break now... but I will see what is up.

thax again..and have a happy thanksgiving.
0
 
LVL 1

Author Comment

by:Danimal
Comment Utility
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.
0
 
LVL 16

Expert Comment

by:JohnBPrice
Comment Utility
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
        OpenLog
        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)
        Else
            LogFile.WriteLine (Format(Now(), "Medium Time") & " - " & msg)
        End If
    Else
        LogFile.WriteBlankLines 1
    End If
End Sub

0
 
LVL 1

Author Comment

by:Danimal
Comment Utility
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.

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now