Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[Func] HTTPRequest: for Web APIs [AHK-B + AHK-L+Unicode+x64]


  • Please log in to reply
380 replies to this topic
fincs
  • Moderators
  • 1662 posts
  • Last active:
  • Joined: 05 May 2007
You forgot the quotes:
httprequest([color=red]"[/color]us.battle.net/api/wow/auction/data/medivh[color=red]"[/color], inOutPost, inOutHeaders, "")

You might want to read the AutoHotkey manual entry on expressions.

Uberi As Guest
  • Guests
  • Last active:
  • Joined: --

I am trying to fetch WoW (World of Warcraft) armoury data with HTTPrequest. It should be just as simple as:

httprequest(us.battle.net/api/wow/auction/data/medivh, inOutPost, inOutHeaders, "")

Unfortunately I am getting the following error: "There was problem with the provided URL(InternetCrackURL). ErrorLevel = 0, A_LastError = 12006"


Try this:

httprequest("us.battle.net/api/wow/auction/data/medivh", inOutPost, inOutHeaders, "")

Strings in expressions need to be enclosed in quotes.

Plqk
  • Members
  • 17 posts
  • Last active: Nov 11 2011 02:49 PM
  • Joined: 08 Jul 2011
Sorry I mislead you a bit... in my code I have it in quotes (I was not directly pasting the code). I still get the error.

Sergio
  • Members
  • 516 posts
  • Last active: Dec 01 2017 04:46 PM
  • Joined: 16 Mar 2008
Firstly, thanks [VxE] for making and maintaining this script.

I hate to ask the beginner question, but is it possible to see an example of something else (which is simpler)? It is the equivalent of URLDownloadToFile, but with a name and password.

In my case, I want to pull back information from eBay.com, but any site will do. For eBay, I know that the POSTDATA for the User name & Password is 'userid' & 'pass'. Any page is good, I just don't know exactly how to set it up.

ahkFooter.png

IF YOU DO NOT GET ANSWERS HERE, TRY; HTTP://AHKSCRIPT.ORG/BOARDS


VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
YW, Sergio. I don't have an example specific to the eBay website (different from eBay's API), but here are a tip for beginners using HTTPRequest.

Tip: Setting up the HTTPRequest call:
; Users are encouraged to utilize continuation sections for readability.
My_URL = https://www.mysecuresite.com/login?dologin=1
My_POST =
( LTRIM C JOIN& ; Join using an ampersand to separate name/value pairs in the forms POST data
    userid=%myuserid%
    pass=%mypassword% ; variable references depend on the assignment operator ( '=' v.s. ':=' )
)
My_Headers =
( LTRIM ; join headers using regular newlines (the default join character).
    my-auth-type: auth-post
    Content-Type: application/x-www-form-urlencoded
)
My_Options =
( LTRIM C ; options should also be separated by newlines.
    +Flag: INTERNET_FLAG_NO_COOKIES
    Callback: MyProgressFunc
)
; Call HTTPRequest. For debugging purposes, copy the POST data (if it is text) to the variable that is going to hold the response.
; If not submitting POST, assign an empty string to the variable that will hold the response.
size := HTTPRequest( My_URL, My_Response := My_POST, My_Headers, My_Options )

A number of bugs and (un)desirable behaviors have been brought to my attention (many thanks, mauritius and dadepp) and I am working on addressing most of them for the next version of HTTPRequest, which I hope to release in the next week or two. The updates should increase usability in cases involving file downloads and codepages other than UTF and english, and it will address problems with the format of the options parameter.

Plqk
  • Members
  • 17 posts
  • Last active: Nov 11 2011 02:49 PM
  • Joined: 08 Jul 2011

Sorry I mislead you a bit... in my code I have it in quotes (I was not directly pasting the code). I still get the error.


Got it to work... forgot I was behind a proxy.

n-l-i-d
  • Guests
  • Last active:
  • Joined: --
Can this be adapted to accept other ports than the default (80, 443)?

Other than that, great library. 8)

Zod
  • Members
  • 214 posts
  • Last active: Jan 26 2012 08:02 PM
  • Joined: 06 Jul 2011

Can this be adapted to accept other ports than the default (80, 443)?

Other than that, great library. 8)

Sorry if I am incorrect but isn't the port part of the URL and left out for the defaults of the protocols

Thanks
Posted Image Stolen from SKAN

Uberi
  • Moderators
  • 1119 posts
  • Last active: May 02 2015 06:05 PM
  • Joined: 23 Aug 2010
Yes, it is possible with URL's in the following format:

SCHEMA://DOMAIN.TLD:PORT/

Where "PORT" is the port number.

n-l-i-d
  • Guests
  • Last active:
  • Joined: --
Hmm, ok, must be an error on my part then.

Thanks.

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
Thanks daonlyfreez and Uberi, I learned something new :lol:

And, here is the long-awaited update: version (9-10-2011).

BugFix: Options parsing.

BugFix: MD5 function now returns the base64 encoded hash. Also, the automatic value for the Content-MD5 header should be correct for the actual POST data even if uploading a file or after codepage conversion.

New Option: Binary: tells HTTPRequest not to do anything special to downloaded text (no codepage conversion).

New Option: Codepage: tells HTTPRequest to convert the POST text to the codepage specified in the 'charset' attribute of the 'Content-Type' request header.

New Option: Upload: (filepath): HTTPRequest will upload the file as POST data, INSTEAD of whatever is in the 'in_POST_out_Data' parameter.

Tweaked Option: Callback: (Function Name)[, param3]: previously, the callback function had to require either one or two parameters. Now the function may require between 0 and 3 parameters. If the function accepts a third parameter, whatever text appears after the name of the callback function is passed as the third parameter.

Tweak: If the callback function returns the word "cancel", HTTPRequest will terminate the transaction, clean up, and return the number of bytes downloaded.

Tweaked Option: [N][R]> (output file): Two modifiers for the output file option change how the download is handled. The 'N' modifier prevents HTTPRequest from reading the file's contents into 'in_POST_out_Data' (convenient for large downloads). The 'R' option is a shortcut for the Range: header, and IF the file exists, HTTPRequest will attempt to resume downloading it.

Tweak: Cookie headers no longer need +INTERNET_FLAG_NO_COOKIES specified in the options.

Tweak: Options flags no longer need the word 'flag:' in front, a single '+' or '-' tells HTTPRequest to look at the option as a flag.

A note about resuming the download: I had considered following dadepp's example more closely and implemented more stringent validity checks. In the end, I decided just to check for the '206 Partial Content' response code before writing to the file.

As always, let me know if you find any bugs.

daonlyfreez
  • Members
  • 995 posts
  • Last active: Jan 23 2013 08:16 AM
  • Joined: 16 Mar 2005
Is somebody willing to test this lib with SABnzbd, a client for that which shall not be mentioned.

It listens on port 8085, and for some weird reason, I cannot connect to it with the lib. SABnzbd has an API, which can be used to control it.

A simple test would be to return the version. For this you do not need the API key (can be found in the program's settings):

searchurl := "http://localhost:8085/sabnzbd/api?mode=version&output=xml"

msgbox % len := HTTPRequest(searchurl, resultData, resultHeaders) . "`n`n" . resultHeaders . "`n`n" . resultData

I get a MsgBox with the following error:

0

There was a problem sending the GET request. ErrorLevel = 0, A_LastError = 12029


I don't get why it doesn't work as expected. :(

Anybody?
Posted Image mirror 1mirror 2mirror 3ahk4.me • PM or Posted Image

Mystiq
  • Members
  • 83 posts
  • Last active: Nov 06 2011 07:07 PM
  • Joined: 08 Jan 2007
@daonlyfreez

I've got no problems getting response. Using latest AHK_L with SABnzbd version 0.6.9. Apart from having APIKEY defined and different host address, it worked on my first try. :shock:

n-l-i-d
  • Guests
  • Last active:
  • Joined: --
@Mystic: thanks for trying.

twhyman
  • Members
  • 348 posts
  • Last active: Sep 17 2014 01:55 AM
  • Joined: 07 Dec 2005
Can someone post a POST example for this URL:
<!-- m -->http://www.w3schools... ... tToCelsius<!-- m -->

And can we use multiple flags, when calling the functions?

Thanks,
Twhyman
(\__/) This is Bunny.
(='.'=) Cut, copy, and paste bunny onto your sig.
(")_(") Help Bunny gain World Domination.