cURL / Mailing Lists / curl-library / Single Mail


(Using libcurl.vb and Excel VBA) GET Response=HTTP/1.1 400 Bad Request

From: Donnell, Grant, AUCKLAND, Information Services <>
Date: Thu, 18 May 2006 15:19:36 +1200


I'm hoping there'll be a simple solution to my problem.

I downloaded the libcurl.vb Internet Client API for Visual Basic 6 and Microsoft Office from Sourceforge and am trying to get it working with Excel 2000 VBA. I have migrated some of the sample/demonstration code to VBA such that it compiles and runs. It appears to connect through our proxy server but I'm stuck with a "400 Bad Request" response to the GET request.

I've included below the debug information provided by cURL and the VBA module code used.

Any suggestions on what may be going wrong and how to fix it would be much appreciated!

Cheers, Grant
-----------------------Start of Debug.Print Output--------------------------------------

info=0, debugMsg=
About to connect() to port 80

info=0, debugMsg=
info=0, debugMsg=

info=0, debugMsg=
Connected to ( port 80

info=2, debugMsg=
Pragma: no-cache
Accept: */*

info=1, debugMsg=
HTTP/1.1 400 Bad Request

info=1, debugMsg=
Server: Microsoft-IIS/5.0

info=1, debugMsg=
Date: Wed, 17 May 2006 23:53:29 GMT

info=1, debugMsg=
Connection: close

info=1, debugMsg=
Content-Type: text/html

info=1, debugMsg=
Content-Length: 87

info=3, debugMsg=
<html><head><title>Error</title></head><body>The parameter is incorrect. </body></html>
info=0, debugMsg=
Closing connection #0

Here's the HTML:
<html><head><title>Error</title></head><body>The parameter is incorrect. </body></html>

--------------------------End of Debug.Print Output-------------------------------------
------------------------Start of EasyGet Module Code------------------------------------
Option Explicit

' $Id: EasyGet.bas,v 1.1 2005/03/01 00:06:26 jeffreyphillips Exp $
' Demonstrate Easy Get Capability

Private Sub Test()
    EasyGet ("")
End Sub

Private Sub EasyGet(url As String)
    Dim easy As Long
    Dim ret As CURLcode
    Dim buf As New Buffer
    easy = VBCurl_Easy_Init()
    VBCurl_Easy_Setopt easy, CURLOPT_URL, url
    VBCurl_Easy_Setopt easy, CURLOPT_PROXY, ""
    VBCurl_Easy_Setopt easy, CURLOPT_WRITEDATA, ObjPtr(buf)
    VBCurl_Easy_Setopt easy, CURLOPT_WRITEFUNCTION, _
        AddressOf WriteFunction
    VBCurl_Easy_Setopt easy, CURLOPT_DEBUGFUNCTION, _
        AddressOf DebugFunction
    VBCurl_Easy_Setopt easy, CURLOPT_VERBOSE, True
    ret = vbcurl_easy_perform(easy)
    VBCurl_Easy_CleanUp easy
    Debug.Print "Here's the HTML:"
    Debug.Print buf.stringData
End Sub

' This function illustrates a couple of key concepts in libcurl.vb.
' First, the data passed in rawBytes is an actual memory address
' from libcurl. Hence, the data is read using the MemByte() function
' found in the VBVM6Lib.tlb type library. Second, the extra parameter
' is passed as a raw long (via ObjPtr(buf)) in Sub EasyGet()), and
' we use the AsObject() function in VBVM6Lib.tlb to get back at it.
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))
    ' Need this line below since AsObject gets a stolen reference
    ObjectPtr(obj) = 0&
    ' Return value
    WriteFunction = totalBytes
End Function

' Again, rawBytes comes straight from libcurl and extra is a
' long, though we're not using it here.
Private Function DebugFunction(ByVal info As curl_infotype, _
    ByVal rawBytes As Long, ByVal numBytes As Long, _
    ByVal extra As Long) As Long
    Dim debugMsg As String
    Dim i As Long
    debugMsg = ""
    For i = 0 To numBytes - 1
        debugMsg = debugMsg & Chr(MemByte(rawBytes + i))
    Debug.Print "info=" & info & ", debugMsg=" & vbCrLf & debugMsg
    DebugFunction = 0
End Function
------------------------ End of EasyGet Module Code ------------------------------------
Received on 2006-05-18