cURL / Mailing Lists / curl-library / Single Mail

curl-library

Multiple post fields VB

From: Perkins, Christopher J <Christopher.J.Perkins_at_questdiagnostics.com>
Date: Mon, 21 Jun 2010 19:00:25 -0400

Hello, I have written code that will work through the command line interface, but when I run it through vb i get to the page, however, I get a system error message from the website itself. I know that I am getting to the page ok, but for some reason it does not like my post data. Here is a sample of the command line code, followed by the vb sample. Can anyone see any issues with this? Any help would be greatly appreciated! Thanks, Chris Command line code (Working): curl -k -s -L -x 111.11.111.1111:9090 -d"RecipID=12345" -d"RecipDOB=01/01/1901" -d"RecipDOI=01/01/2010" -d"RecipDOS=01/01/2010" -d"Submit=SUBMIT" -d"UserID=ABCDE" -d"UserPW=12345" -b"UserID=ABCDEF; UserPW=12345; LastTime=6%2F19%2F2010+1%3A35%3A24+PM; OwnerNum=01" https://www.medi-cal.ca.gov/Eligibility/EligResp.asp <https://www.medi-cal.ca.gov/Eligibility/EligResp.asp> VB Code (Not Working): Private Sub Test() Call SSLGet("https://www.medi-cal.ca.gov/Eligibility/EligResp.asp") End Sub Private Sub SSLGet(url As String, Optional caFile As String) Dim context As Long Dim ret As Long Dim buf As New Buffer Dim RecipID As String, RecipDOB As String, RecipDOI As String, RecipDOS As String RecipID = "12345" RecipDOB = "01/01/1901" RecipDOI = "01/01/2010" RecipDOS = "01/01/2010" context = vbcurl_easy_init() vbcurl_easy_setopt context, CURLOPT_TIMEOUT, 30 If caFile <> Null Then vbcurl_easy_setopt context, CURLOPT_CAINFO, caFile Else vbcurl_easy_setopt context, CURLOPT_SSL_VERIFYPEER, False End If vbcurl_easy_setopt context, CURLOPT_FOLLOWLOCATION, True vbcurl_easy_setopt context, CURLOPT_VERBOSE, True vbcurl_easy_setopt context, CURLOPT_PROXY, "111.11.111.1111:9090 " vbcurl_easy_setopt context, CURLOPT_POSTFIELDS, "RecipID=" & RecipID vbcurl_easy_setopt context, CURLOPT_POSTFIELDS, "RecipDOB=" & RecipDOB vbcurl_easy_setopt context, CURLOPT_POSTFIELDS, "RecipDOI=" & RecipDOI vbcurl_easy_setopt context, CURLOPT_POSTFIELDS, "RecipDOS=" & RecipDOS vbcurl_easy_setopt context, CURLOPT_POSTFIELDS, "Submit=SUBMIT" vbcurl_easy_setopt context, CURLOPT_POSTFIELDS, "UserID=ABCDEF" vbcurl_easy_setopt context, CURLOPT_POSTFIELDS, "UserPW=12345" vbcurl_easy_setopt context, CURLOPT_POST, 1 'Below tried to post fields all together based on instructions online, didn't work. ' vbcurl_easy_setopt context, CURLOPT_POSTFIELDS, "RecipID=" & RecipID & "RecipDOI=" & RecipDOI & "RecipDOS=" & RecipDOS & "Submit=SUBMIT&UserID=ABCDEF&UserPW=12345" ' vbcurl_easy_setopt context, CURLOPT_POST, 1 vbcurl_easy_setopt context, CURLOPT_COOKIE, "UserID=ABCDEF; UserPW=12345; LastTime=" & urlencode(CStr(Date & " " & Time)) & "; OwnerNum=01" vbcurl_easy_setopt context, CURLOPT_URL, url vbcurl_easy_setopt context, CURLOPT_WRITEFUNCTION, _ AddressOf WriteFunction vbcurl_easy_setopt context, CURLOPT_WRITEDATA, ObjPtr(buf) vbcurl_easy_setopt context, CURLOPT_NOPROGRESS, 0 vbcurl_easy_setopt context, CURLOPT_PROGRESSFUNCTION, _ AddressOf ProgressFunction ret = vbcurl_easy_perform(context) vbcurl_easy_cleanup context Debug.Print "Here's the SSL HTML:" Debug.Print buf.stringData myfile = "C:\databases\output.html" Open myfile For Output As #1 Print #1, buf.stringData Close #1 End Sub ' See WriteFunction() in EasyGet.bas for more detailed explanation. Private Function WriteFunction(ByVal rawBytes As Long, _ ByVal sz As Long, ByVal nmemb As Long, _ ByVal extra As Long) As Long Dim totalBytes As Long, i As Long Dim obj As Object, buf As Buffer totalBytes = sz * nmemb Set obj = AsObject(extra) Set buf = obj ' append the binary characters to the HTML string For i = 0 To totalBytes - 1 ' Append the write data buf.stringData = buf.stringData & Chr(MemByte(rawBytes + i)) Next ' Need this line below since AsObject gets a stolen reference ObjectPtr(obj) = 0& ' Return value WriteFunction = totalBytes End Function Private Function ProgressFunction(ByVal extra As Long, _ ByVal dlTotal As Double, ByVal dlNow As Double, _ ByVal ulTotal As Double, ByVal ulNow As Double) As Long ' just print the data Debug.Print "dlTotal=" & dlTotal & ", dlNow=" & dlNow & _ ", ulTotal=" & ulTotal & ", ulNow=" & ulNow ProgressFunction = 0 End Function Public Function urlencode(sText As String) As String 'This function converts non-alphanumeric characters to their 'hexadecimal equivalents, as required by http protocol. Dim sTemp As String Dim sAns As String Dim sChar As String Dim lctr As Long For lctr = 1 To Len(sText) sChar = Mid$(sText, lctr, 1) 'is it alphanumeric If sChar Like "[0-9A-Za-z]" Then sTemp = sTemp & sChar ElseIf sChar = " " Then sTemp = sTemp & "+" ElseIf True Then sTemp = sTemp & "%" & Right$("0" & Hex(Asc(sChar)), 2) End If If Len(sTemp) > 1000 Then sAns = sAns & sTemp sTemp = "" End If Next urlencode = sAns & sTemp End Function ------------------------------------------ The contents of this message, together with any attachments, are intended only for the use of the person(s) to which they are addressed and may contain confidential and/or privileged information. Further, any medical information herein is confidential and protected by law. It is unlawful for unauthorized persons to use, review, copy, disclose, or disseminate confidential medical information. If you are not the intended recipient, immediately advise the sender and delete this message and any attachments. Any distribution, or copying of this message, or any attachment, is prohibited.

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-06-22