HTTP Library (Crossplatform, GET/HEAD/POST, chunked, gzip)

Share your advanced PureBasic knowledge/code with the community.
Oxyandy
User
User
Posts: 10
Joined: Wed Jun 26, 2013 5:15 pm

Re: HTTP Library (Crossplatform, GET/HEAD/POST, chunked, gzi

Post by Oxyandy »

DarkPlayer

Thank you for the response, I read it about 6-7 hours ago, I have spent the best part of that time reading and making attempts to get something to work

Time for a coffee & clear my head a bit, haven't given up yet, more I can try some of my attempts have been close, lol

So I've made this post in the hope that maybe someone with more experience can make some use of my observations so far and give me a boost in the right direction ?? :D
I really would like everything to be in the one exe.

Thanks
[SOLVED]
Last edited by Oxyandy on Thu Jul 04, 2013 6:05 pm, edited 2 times in total.
[url]irc://freenode/purebasic[/url]
Oxyandy
User
User
Posts: 10
Joined: Wed Jun 26, 2013 5:15 pm

Re: HTTP Library (Crossplatform, GET/HEAD/POST, chunked, gzi

Post by Oxyandy »

Compared to 4. (as in last post) with WireShark I got this from Curl

Code: Select all

POST /upload/in HTTP/1.1
User-Agent: Curl
Host: mysite
Accept: */*
Content-Type: multipart/form-data; boundary=----------------------------b87ebc3d2679

------------------------------b87ebc3d2679
Content-Disposition: form-data; name="fileupload1"; filename="Filename.zip"
Content-Type: application/octet-stream

<data of file snipped from here>
------------------------------b87ebc3d2679
Content-Disposition: form-data; name="press"

Upload files
------------------------------b87ebc3d2679--
Nice shows me "press" with 2 #CRLF$ before
Upload files

More to work with, going to try now
Last edited by Oxyandy on Thu Jul 04, 2013 6:06 pm, edited 1 time in total.
[url]irc://freenode/purebasic[/url]
Oxyandy
User
User
Posts: 10
Joined: Wed Jun 26, 2013 5:15 pm

Re: HTTP Library (Crossplatform, GET/HEAD/POST, chunked, gzi

Post by Oxyandy »

Well I know there are no good posts about PB and Uploading files,
but let me assure anyone, it does work, and works very well !!
Even with Binary files of course !

Dont give up, and use WireShark it will show you what you are doing wrong !
I don't use the libs posted in this thread, but I really respect the detail..

Thanks for sharing to the community
[url]irc://freenode/purebasic[/url]
ozzie
Enthusiast
Enthusiast
Posts: 429
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

Re: HTTP Library (Crossplatform, GET/HEAD/POST, chunked, gzi

Post by ozzie »

Many thanks for this library, DarkPlayer. It's just what I need for communicating with vMix as mentioned here.
Sebert
New User
New User
Posts: 8
Joined: Wed Mar 26, 2014 2:50 pm

Re: HTTP Library (Crossplatform, GET/HEAD/POST, chunked, gzi

Post by Sebert »

First of all: Thank you for this Library !

EDIT/SOLVED: Sometimes writing things down is all you need to do to spot the problem.
There were some forbidden characters (":") in the filename. :oops:

I am quite new to PureBasic, I have some experience with VBA, SQL & Java though.

As an excercise I am writing a little Podcast downloader.
So far it works fine, it reads a config XML file, where the urls of the podcast feeds are stored.
Then it downloads the xml/rss file of the podcast, and reads the propertys of the items/episodes.
The plan was/is to download the single mp3 using the urls from the feed.
But somehow this doesnt't always work, the download progresses as planned, but in
the end there is nothing but a 0 kb file without an extension.

Code: Select all

Downloading to file 'J:\PodcastTest\hr-iNFO Wissenswert\Meilensteine der Popmusik - Talking Heads: Psycho Killer (1977).mp3'
Progress: 0.0000000000
Progress: 0.0752758682
Progress: 0.1505517364
Progress: 0.2258276045
Progress: 0.3011034727
Progress: 0.3763793409
Progress: 0.4516552091
Progress: 0.5269311070
Progress: 0.6022069454
Progress: 0.6774828434
Progress: 0.7527586818
Progress: 0.8280345798
Progress: 0.9033104181
Progress: 0.9785863161
This results in a 0 kb file "J:\PodcastTest\hr-iNFO Wissenswert\Meilensteine der Popmusik - Talking Heads: Psycho Killer (1977)"

Here is my basic code:

Code: Select all

XIncludeFile "disconnect.pbi" ;Must be in front of all HTTP Query Includes!!
XIncludeFile "http.pbi"
InitNetwork()
Define overwrite
Define.s EntryUrl,Ordner

EntryUrl = "http://mp3.podcast.hr-online.de/mp3/podcast/hr2_wissenswert/hr2_wissenswert_20140322_3.mp3"
Ordner = "J:\PodcastTest\hr-iNFO Wissenswert\Meilensteine der Popmusik - Talking Heads: Psycho Killer (1977).mp3"
SimpleHTTP_GET_File(EntryUrl, Ordner, overwrite.i = #True)
It works fine with other podcasts though.
Any idea/diagnosis on what may be the problem there ?

Best regards

Sebert
Sebert
New User
New User
Posts: 8
Joined: Wed Mar 26, 2014 2:50 pm

Re: HTTP Library (Crossplatform, GET/HEAD/POST, chunked, gzi

Post by Sebert »

Hi,

another question: I get "The connection aborted/timed out during the transfer!" for some files which download
just fine via browser or ReceiveHTTPFile. Is there a way to give the "SimpleHTTP_GET_File" Procedure a bit more
time to download?

Regards

Sebastian
said
Enthusiast
Enthusiast
Posts: 342
Joined: Thu Apr 14, 2011 6:07 pm

Re: HTTP Library (Crossplatform, GET/HEAD/POST, chunked, gzi

Post by said »

Thanks for this excellent lib! Works great :D
I had to do minor modifications (e.g Content-Type allowing for application/json to pass ...) and it worked fine where cURL failed!

Hopefully the PB team will take your notes into consideration when developing a native HTTP (i said hopefully ... soon :wink: :?: )

Thanks again :)
Liqu
User
User
Posts: 77
Joined: Sun Apr 21, 2013 10:31 am

Re: HTTP Library (Crossplatform, GET/HEAD/POST, chunked, gzi

Post by Liqu »

i'm still lost about how to upload file ( for example a text/ jpg / zip file ) using SimpleHTTP_POST_RAW and SimpleHTTP_POST
would you please show me a complete example from html -> php -> pb, please

i tried using this, but failed :

Update /

i've been successfuly post text file / string
maybe i'll encrypt the content before POST it so it will be text friendly and decompress it online.

Thank you very much :)
normeus
Enthusiast
Enthusiast
Posts: 415
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: HTTP Library (Crossplatform, GET/HEAD/POST, chunked, gzi

Post by normeus »

does any one have a working example of SimpleHTTP_POST_RAW from this library?


[edited to delete my not working example]

Thank you.
Norm.
Last edited by normeus on Mon Mar 23, 2015 8:48 pm, edited 1 time in total.
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: HTTP Library (Crossplatform, GET/HEAD/POST, chunked, gzi

Post by infratec »

Hi,

without checking in real:

If you send a file, you need "Content-length:" in the header.
Or you use chunks, but then you need "Transfer-Encoding: chunked".

Maybe you need also to tell the server tahtyou send it Base64 encoded.

But I would send it as binary, because it is much faster (shorter).

Bernd
Aming
New User
New User
Posts: 3
Joined: Fri Nov 02, 2012 10:02 am

Re: HTTP Library (Crossplatform, GET/HEAD/POST, chunked, gzi

Post by Aming »

Anyone who can make it support https? Thanks a lot.
Poshu
Enthusiast
Enthusiast
Posts: 459
Joined: Tue Jan 25, 2005 7:01 pm
Location: Canada

Re: HTTP Library (Crossplatform, GET/HEAD/POST, chunked, gzi

Post by Poshu »

Aming wrote:Anyone who can make it support https? Thanks a lot.
That would be quite a lot of work, I don't think anyone has this kind of free time.
normeus
Enthusiast
Enthusiast
Posts: 415
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: HTTP Library (Crossplatform, GET/HEAD/POST, chunked, gzi

Post by normeus »

infratec posted this link for HTTPS and it has worked for me ( to post/request data from googlemaps)

http://www.purebasic.fr/english/viewtop ... 13&t=58824


Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
User avatar
tj1010
Enthusiast
Enthusiast
Posts: 624
Joined: Mon Feb 25, 2013 5:51 pm
Location: US or Estonia
Contact:

Re: HTTP Library (Crossplatform, GET/HEAD/POST, chunked, gzi

Post by tj1010 »

It needs all fingerprint functions updated and you can now implement SSL/TLS fallback for GET using PB functions.

EDIT: Some sites/servers use multiple Set-Cookie headers even though I believe this is against spec.. Index parameter for request header function?
The truth hurts.
Post Reply