Close

Results 1 to 11 of 11
  1. #1
    DF Member Plasma's Avatar
    Join Date
    Oct 2002
    Location
    Planet Earth
    Posts
    37
    Thanks
    0
    Thanked:        0
    Karma Level
    0

    Default Custom HTTP Headers In Visual Basic

    Hi wonder if there are any VB programming guru's out there that can assist me.

    I have written a small application that controls a CTI enabled PBX telephone via the PC using a special server and HTTP requests. You don't need to know the in's and out's so I won't bore you with the details.

    Basically when you click buttons on the form it sends HTTP requests in the form of a URL to a CTI Server for e.g.

    http://www.myserver.co.uk/make?9123 (To dial the speaking clock)
    http://www.myserver.co.uk/clear (To hang up a call)
    http://www.myserver.co.uk/answer (To answer incoming calls)

    etc etc....

    I've been asked by the people who manage http://www.myserver.co.uk if when I send the requests I can include a custom HTTP header with for example a "Referer" field and "my_program_name" as the data for the referer, so that they know which application the requests are coming from. I've scoured the MSDN Library & Tech Net, to no avail.

    I've been using both the msinet.ocx (MS Internet Transfer Controls) plugin and the shdocvw.dll (MS Internet Controls) plugin from Visual Basic 6 SP5. If anyone can suggest a way to do it or a different control I'd be enormously grateful!

    Hope it makes sense to someone!

    Regards

    Plasma

  2. #2
    DF VIP Member graham.edmon's Avatar
    Join Date
    May 2001
    Location
    Edinburgh
    Posts
    263
    Thanks
    0
    Thanked:        0
    Karma Level
    290

    Default

    With a reference to MSXML2 set, you can use later versions of the DOM, but the implementation is slightly different.

    Dim oXMLHTTP As XMLHTTPRequest

    Set oXMLHTTP = New XMLHTTPRequest
    Set oXMLDOM = New DOMDocument

    oXMLHTTP.Open "GET", "myurl.co.uk", True, "", ""

    oxmlhttp.setRequestHeader "Referer","program1"
    oXMLHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"

    oXMLHTTP.send "MessageXML=somethingURLencoded"

    Do While oXMLHTTP.readyState <> 4
    DoEvents
    Loop
    If (oXMLHTTP.Status = HTTP_OK) Then
    'Success
    Else
    ' Failed
    End If

  3. #3
    DF Member Plasma's Avatar
    Join Date
    Oct 2002
    Location
    Planet Earth
    Posts
    37
    Thanks
    0
    Thanked:        0
    Karma Level
    0

    Default

    Cheers m8,

    It looks rather complex (only been programming VB for 6 months) but I think I understand the gist of it. I'll give it a whirl when I get back to work on Monday and let you know how I get on!

    One thing, when I use the Inet or the Internet plugin, it automatically sends the Explorer cookie stored on my PC for the CTI server, will this do the same? I guess I'll know on Monday anyway!

    Again, many thanks for the reply.

    Plasma

  4. #4
    DF VIP Member graham.edmon's Avatar
    Join Date
    May 2001
    Location
    Edinburgh
    Posts
    263
    Thanks
    0
    Thanked:        0
    Karma Level
    290

    Default

    yes, it shall... it will send everything IE would send.. all you are doing is manipulating or changing the headers.. the only thing is.. is the session.. cookies exist to a domain and session under a expiration (sometimes infinity), so your code would have to load in the context of the session. its quite complex sometimes.. what are you storing in the cookies?

    if you were using ASP it wouldn't be an issue, you could use VB and obtain an ASP context via the ASP type library (would only run on a computer with IIS running).

    are you confused yet? sorry, if you are. If you can give me a better idea of what you are trying to accomplish, and what environment you are using it in. I would be in a better position to help you come to a solution.

  5. #5
    DF Member Plasma's Avatar
    Join Date
    Oct 2002
    Location
    Planet Earth
    Posts
    37
    Thanks
    0
    Thanked:        0
    Karma Level
    0

    Default

    Hi,
    Sorry its taken me so long to reply, been moving house and having a baby!

    I tried the code you gave me and I get an error ....

    "User-defined type not defined" with regard to:

    Dim oXMLHTTP As XMLHTTPRequest

    Do I need to load a plugin or something first I basically did this:


    Private Sub Command1_Click()

    Dim oXMLHTTP As XMLHTTPRequest

    Set oXMLHTTP = New XMLHTTPRequest
    Set oXMLDOM = New DOMDocument

    oXMLHTTP.Open "GET", "http://myserver.co.uk/answer", True, "", ""

    oXMLHTTP.setRequestHeader "Referer", "program1"
    oXMLHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"

    oXMLHTTP.send "MessageXML=somethingURLencoded"

    Do While oXMLHTTP.readyState <> 4
    DoEvents
    Loop
    If (oXMLHTTP.Status = HTTP_OK) Then
    'Success
    Else
    ' Failed
    End If
    End Sub


    You simply send the "http://www.myserver.co.uk/answer" and it answers the call. The intelegence is in the distant server .. all I need to be able to do is send the request .... I don't even need the response from the remote server, however under certain circumstances it would be better if I could. I currently do it like this using the "Microsoft Internet Controls" shdocvw.dll ....

    WebBrowser1.Navigate "http://myserver.co.uk/answer"

    All I need to be able to do is send the "referer" in the header aswell.

    Regards

    Plasma

  6. #6
    DF VIP Member graham.edmon's Avatar
    Join Date
    May 2001
    Location
    Edinburgh
    Posts
    263
    Thanks
    0
    Thanked:        0
    Karma Level
    290

    Default

    you need to set a reference to the Microsoft XML Dom dll, code below is for MS XML 3 I think.. Goto Project, choose references and tick the entry for MS XML 3.

    should be ok then..

  7. #7
    DF Member Plasma's Avatar
    Join Date
    Oct 2002
    Location
    Planet Earth
    Posts
    37
    Thanks
    0
    Thanked:        0
    Karma Level
    0

    Default

    Thanks Graham,

    I tried referencing XML 3.0, and XML 2.6 got the same error....

    However when I referenced MS XML 2.0 it looks like its working!

    Can't test it till I get back to work, but definately looks like it works, got a firewall alert at home when I ran it.

    I'll be off this week as my wife is having our first baby tomorrow,
    but hopefully will be back in next week and can test it then!

    Will post back and let you know how I get on!

    Thanks Again

    Plasma

  8. #8
    DF VIP Member graham.edmon's Avatar
    Join Date
    May 2001
    Location
    Edinburgh
    Posts
    263
    Thanks
    0
    Thanked:        0
    Karma Level
    290

    Default

    erm, yes.. its MSXML... really it should MSXML2 or above.. for security reasons, but I am sure the model has DOM changed some what in between.... see how it goes or you... should work fine..

    make sure the receiving servers are patched!!

  9. #9
    DF Member Plasma's Avatar
    Join Date
    Oct 2002
    Location
    Planet Earth
    Posts
    37
    Thanks
    0
    Thanked:        0
    Karma Level
    0

    Default

    Graham,

    Right I've managed to get this fully integrated into my application now, and its working a treat! Still as XML 2.0 but I can live with that. I have however found a slight problem that you may or may not be able to answer...

    When using the MSInet.ocx control I could pre define the "Proxy Settings" to either, IE Defaults, Direct, or Named Proxy. when using the XML way it always uses the IE Defaults. This is causing me a few problems as when the proxy goes down my program doesn't work, and also there is sometimes a delay on the proxy server. I'd prefer to be able to send the requests direct and bypass the proxy. As we don't need a proxy for Intranet sites, hence this would be better.

    Any help would be greatly recieved!

    Plasma

  10. #10
    DF VIP Member graham.edmon's Avatar
    Join Date
    May 2001
    Location
    Edinburgh
    Posts
    263
    Thanks
    0
    Thanked:        0
    Karma Level
    290

    Default

    well, I would say in the first instance you can't.. but I shall put my thinking cap on...

    .Net has name spaces that would do it the way you want it..

  11. #11
    DF Member Plasma's Avatar
    Join Date
    Oct 2002
    Location
    Planet Earth
    Posts
    37
    Thanks
    0
    Thanked:        0
    Karma Level
    0

    Default

    I have the 7 CD edition of VB .NET .. looks a bit scary!

    Almost like a different language, maybe I will have to re-visit it.

    Couldn't understand how the format of the project worked, must admit though, I only gave it about 5 mins of my time!

    The last time I tried to convert it to .NET it all went pear shaped.

    It didn't like the way I'd opened a listen socket with mswinsock, and I couldn't work out a way round it. ... The only two complex things are the TCP Listen socket and the HTTP Request, the rest of the program is just cosmetic!

    I might re-install it tonight and run my project through the conversion wizard again.....

    Plasma

Similar Threads

  1. http://www.kentpaul.com/
    By marcode in forum The Dog and Duck
    Replies: 0
    Last Post: 21st September 2002, 08:14 PM
  2. visual basic 6 enterprise
    By spade2001 in forum Programming
    Replies: 21
    Last Post: 14th September 2002, 10:51 AM
  3. Basic P4 Setup Suggestions
    By wizer in forum PC Hardware
    Replies: 0
    Last Post: 9th September 2002, 12:00 PM
  4. Visual basic Any one!
    By magic1 in forum The Dog and Duck
    Replies: 2
    Last Post: 8th September 2002, 02:05 PM

Social Networking Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •