Jump to content


Photo

Http Dll 2


  • Please log in to reply
201 replies to this topic

#1 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 02 June 2011 - 12:42 AM

A long time ago I created Http Dll, but that dll was rather difficult to use. So I've created a completely new version which is easier to use and has a lot more features. Since I was already using sockets internally, I decided to add functions to access them. Of course you also need buffers to manipulate the binary data, so I added those as well.

Features:

  • Http requests
    • Allows you to download web pages or files without blocking the game.
    • Allows you to set request headers and post parameters.
    • Allows you to read the status code, response headers and of course the message body.
    • Supports file uploads.
  • Sockets
    • Supports listening sockets (server) and normal sockets (client).
    • Supports IPv4 and IPv6.
    • Supports TCP and UDP.
  • Buffers: very similar to 39dll, but with a few extra data types.
  • MD5 and SHA-1
  • ZLib compression
  • RC4 encryption
  • Hexadecimal and base64 encoding/decoding

The DLL also fixes an annoying bug/feature in 39dll that can cause data to be lost. With 39dll, the maximum amount of data that can be recieved as a whole is limited by the operating system. Windows will only buffer a fixed amount of data, e.g. 64KB. This might not be enough if you're trying to send large files. If too much data is buffered by the receiver, the sender has to wait to send more data. Since 39dll's sendmessage function doesn't wait, part of the data is lost if too much data is sent at once. This DLL does additional buffering to avoid this problem, so no data is ever lost. You can buffer as much data as you want on both the sending side and the receiving side.

Unlike Http Dll, Http Dll 2 doesn't use a separate thread. I've changed this because it was confusing, and the advantage wasn't that big.

Latest version:
Download Http Dll 2.3 release 6 (with source code)

Older versions:
Download Http Dll 2.2 (with source code)
Download Http Dll 2.1 (with source code)
Download Http Dll 2.0 (with source code)

Documentation:
http://www.maartenba...lls/http-dll-2/

License
lgpl-v3.png
Http Dll 2 is distributed under the terms of the GNU Lesser General Public License.


Edited by Maarten Baert, 25 April 2015 - 03:45 PM.

  • 17
Posted Image

#2 Knuked

Knuked

    GMC Member

  • New Member
  • 242 posts
  • Version:GM:HTML5

Posted 02 June 2011 - 01:19 AM

Windows will only buffer a fixed amount of data, e.g. 64KB. This might not be enough if you're trying to send large files. If too much data is buffered by the receiver, the sender has to wait to send more data. Since 39dll's sendmessage function doesn't wait, part of the data is lost if too much data is sent at once. This DLL does additional buffering to avoid this problem, so no data is ever lost.


One of the absolute worst things about the 39dll in my opinion, not that my opinion matters much ;)

Anyhow Maarten, I hope this is a bit easier, the last one was rather difficult to use and I appreciate you noticing that and attempting to rectify. You bring a lot to this community with all your dlls' and hard work and for that I thank you friend. Plus one to you! I will most certainly give this thing another try :)

Edited by Knuked, 02 June 2011 - 01:20 AM.

  • 0

#3 Mayhem Games

Mayhem Games

    Proud Kiwi

  • GMC Member
  • 959 posts
  • Version:GM:Studio

Posted 02 June 2011 - 04:04 AM

Looks much better than the original :) I haven't tried this out properly yet but do have plans for it in an upcoming project. This update may just make it one of my favorite Game Maker dll's :lol:
  • 0

For a long time it puzzled me how something so expensive, so leading edge, could be so useless, and then it occurred to me that a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a dangerously perfect match. ~ Bill Bryson


#4 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 3578 posts
  • Version:GM:Studio

Posted 02 June 2011 - 01:52 PM

A must-have on my DLLs folder and a must-use on most of my games, this post has been tagged :)
  • 0

@MEtchegaray7

gplussignature.png

May this signature be frozen on the old GMC until the end of times. Or YoYo takes it down.


#5 sinny

sinny

    GMC Member

  • New Member
  • 17 posts

Posted 02 June 2011 - 06:00 PM

I'm looking to either fix or dump my usage of 39dll, as I've just started testing a small project using it and I'm noticing what appears to be lag when only transferring a couple of numbers between client and server (for movement). I know this can't be right, so I assume I'm either using it incorrectly, or otherwise, but for now I'll have a play with this and see what it's like.

There aren't any installation instructions that I can find; I know this is easy for old hands but I'm only a month into GM. Any simple procedure?
  • 0

#6 Medo42

Medo42

    GMC Member

  • GMC Member
  • 322 posts

Posted 02 June 2011 - 07:06 PM

I'm looking to either fix or dump my usage of 39dll, as I've just started testing a small project using it and I'm noticing what appears to be lag when only transferring a couple of numbers between client and server (for movement). I know this can't be right, so I assume I'm either using it incorrectly, or otherwise, but for now I'll have a play with this and see what it's like.

Did you try to disable Nagle's algorighm? IIRC the command for that is setnagle(1), paradoxically.

Generally I have to say, this dll does look very good. I didn't look at everything yet, but this is the only dll/extension I know besides Faucet Networking that handles reading from and writing to sockets in a sane manner.
  • 0

#7 sinny

sinny

    GMC Member

  • New Member
  • 17 posts

Posted 03 June 2011 - 11:18 AM

I'm looking to either fix or dump my usage of 39dll, as I've just started testing a small project using it and I'm noticing what appears to be lag when only transferring a couple of numbers between client and server (for movement). I know this can't be right, so I assume I'm either using it incorrectly, or otherwise, but for now I'll have a play with this and see what it's like.

Did you try to disable Nagle's algorighm? IIRC the command for that is setnagle(1), paradoxically.


Oh good god that is insane. Totally fixed it. Uh, thanks.
  • 0

#8 regular

regular

    GMC Member

  • New Member
  • 399 posts

Posted 10 June 2011 - 08:14 AM

What can be the reason this code not to work?
http_dll_2_1_init();
rq=httprequest_create();
httprequest_connect(rq,"http://randomsite.com/randompage.php?argument1=blah",0);
var st;
while(1) 
   {
    httprequest_update(rq);
    st = httprequest_get_state(rq);
    if st==4 || st==5 break;
    sleep(10);
   }
if st!=5 show_message(httprequest_get_message_body(rq));else {show_message(":C    :<    :(");show_message(httprequest_get_message_body(rq));}
httprequest_destroy(rq);
It always shows those emoticons >.>
  • 0

suno li walo
ale li pona


#9 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 11 June 2011 - 11:03 AM

It works for me ...

Make sure the server is online, and make sure your firewall isn't blocking your game.
  • 1
Posted Image

#10 regular

regular

    GMC Member

  • New Member
  • 399 posts

Posted 11 June 2011 - 03:46 PM

Yeah, it turned out my website got deleted.
Anyway, I got another question: How do I make the dll ignore the html tags such as <!-- --> and <script> </script>? My webhost is putting them automatically and this only wastes bandwidth and time to send. >.>
  • 0

suno li walo
ale li pona


#11 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 13 June 2011 - 10:35 AM

You should filter them out manually with string functions. The easiest way to do this is to add a special 'marker' to your own data, so you can see where your data starts and ends. Like this:
echo "<----begin---->";
// (now echo your data)
echo "<----end---->";
Then you can use this script to remove the garbage:
// remove_garbage(str)
var marker_begin, marker_end, p1, p2;
marker_begin = "<----begin---->";
marker_end = "<----end---->";
p1 = string_pos(marker_begin, argument0);
p2 = string_pos(marker_end, argument0);
if p1=0 or p2<p1+string_length(marker_begin) {
    return "";
} else {
    return string_copy(argument0, p1+string_length(marker_begin), p2-p1-string_length(marker_begin));
}

Edited by Maarten Baert, 13 June 2011 - 10:37 AM.

  • 0
Posted Image

#12 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • GMC Elder
  • 9603 posts
  • Version:GM:Studio

Posted 13 June 2011 - 01:02 PM

I haven't tested this yet, but I liked v1 of the DLL, so I can't imagine I would dislike this ;) .

However, before I test it, I did have a question. This DLL has an MD5 hash algorithm built-in. Would it be possible to also include HMAC-SHA1? This is used for many OAuth systems (the security system of choice for most big online services nowadays), so including it would make integration with well-known services much easier.

I found a SHA1 DLL here: http://gmc.yoyogames...dpost&p=1080503 , so making an HMAC using that shouldn't be too hard, but I'd rather not use 2 separate DLLs for one function, especially since MD5 is already included.

-IMP ;) :)

*EDIT* You know that whole part about "shouldn't be too hard to make the HMAC script"? I was wrong. My attempt ended up with the same unresolved issue found here: http://gmc.yoyogames...howtopic=484442 . So please, please, please, add in HMAC-SHA1 hashing, please.

Edited by IceMetalPunk, 13 June 2011 - 01:18 PM.

  • 0

:GM123: Are you an artist who likes creating original creature designs? Maybe you can help out with Elementa here! Give it a look; you might like the idea :)

:bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny:


#13 Jub Jub

Jub Jub

    GMC Member

  • GMC Member
  • 15 posts

Posted 15 June 2011 - 02:43 AM

Excellent, this DLL looks exactly like what I was looking for. :) Thanks!
  • 0
How many people are playing your game right now? Find out with Clockwork.

#14 regular

regular

    GMC Member

  • New Member
  • 399 posts

Posted 15 June 2011 - 04:55 PM

I got another problem - when I open my website with the browser, the php's echoes text is displayed, but when I try to get the result of the same addres ingame with httprequest_get_message_body, it returns an empty string "". The scripts were working correctly, but then the website was took down for a while to be approved - when it got back online, it simply stopped replying to the game. Why is this? I think the problem lies in the scripts, could it be somewhere else?
  • 0

suno li walo
ale li pona


#15 locohost

locohost

    GMC Member

  • GMC Member
  • 459 posts
  • Version:GM:Studio

Posted 15 June 2011 - 11:03 PM

Link is dead :(
  • 0

#16 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 16 June 2011 - 03:44 PM

@locohost: The link works for me ...

I got another problem - when I open my website with the browser, the php's echoes text is displayed, but when I try to get the result of the same addres ingame with httprequest_get_message_body, it returns an empty string "". The scripts were working correctly, but then the website was took down for a while to be approved - when it got back online, it simply stopped replying to the game. Why is this? I think the problem lies in the scripts, could it be somewhere else?

Try setting the User-Agent header to the User-Agent of an existing browser (e.g. "Mozilla/5.0"). Maybe the website doesn't respond to requests without a 'real' user agent (I've seen this a few times).

@IceMetalPunk:
Adding SHA-1 shouldn't be that hard, I will try it.

If I understand correctly, it works like this:
HMAC-MD5(message, key) = MD5(opad(key)+MD5(ipad(key)+message))
But I think MD5 is supposed to return a 16-byte binary string instead of a 32-byte hexadecimal string. You can do that with buffer_write_hex. I wrote a script for HMAC-MD5 and it gives the same results as PHP, so I think it works :).
// hmac_md5_string(message, key);
var b, i, c, h;

b = buffer_create();
c = min(string_length(argument1), 64);

// ipad
for(i = 0; i<c; i += 1) {
    buffer_write_uint8(b, ord(string_char_at(argument1, i+1))^$36);
}
for(i = c; i<64; i += 1) {
    buffer_write_uint8(b, $36);
}

// first hash
md5_begin();
md5_read_buffer(b);
md5_read_string(argument0);
md5_end();
h = md5_result();
buffer_clear(b);

// opad
for(i = 0; i<c; i += 1) {
    buffer_write_uint8(b, ord(string_char_at(argument1, i+1))^$5c);
}
for(i = c; i<64; i += 1) {
    buffer_write_uint8(b, $5c);
}
buffer_write_hex(b, h);

// second hash
md5_begin();
md5_read_buffer(b);
md5_end();
h = md5_result();

buffer_destroy(b);

return h;
Alternatively, if you want to calculate the HMAC of a buffer:
// hmac_md5_buffer(messagebuffer, key);
var b, i, c, h;

b = buffer_create();
c = min(string_length(argument1), 64);

// ipad
for(i = 0; i<c; i += 1) {
    buffer_write_uint8(b, ord(string_char_at(argument1, i+1))^$36);
}
for(i = c; i<64; i += 1) {
    buffer_write_uint8(b, $36);
}

// first hash
md5_begin();
md5_read_buffer(b);
md5_read_buffer(argument0);
md5_end();
h = md5_result();
buffer_clear(b);

// opad
for(i = 0; i<c; i += 1) {
    buffer_write_uint8(b, ord(string_char_at(argument1, i+1))^$5c);
}
for(i = c; i<64; i += 1) {
    buffer_write_uint8(b, $5c);
}
buffer_write_hex(b, h);

// second hash
md5_begin();
md5_read_buffer(b);
md5_end();
h = md5_result();

buffer_destroy(b);

return h;

Edited by Maarten Baert, 16 June 2011 - 03:46 PM.

  • 2
Posted Image

#17 locohost

locohost

    GMC Member

  • GMC Member
  • 459 posts
  • Version:GM:Studio

Posted 16 June 2011 - 04:01 PM

Wow thanks Maarten for that really useful reply!

Here is what I see when I click the link...

Download Link Broken
  • 0

#18 regular

regular

    GMC Member

  • New Member
  • 399 posts

Posted 16 June 2011 - 04:59 PM

I got another problem - when I open my website with the browser, the php's echoes text is displayed, but when I try to get the result of the same addres ingame with httprequest_get_message_body, it returns an empty string "". The scripts were working correctly, but then the website was took down for a while to be approved - when it got back online, it simply stopped replying to the game. Why is this? I think the problem lies in the scripts, could it be somewhere else?

Try setting the User-Agent header to the User-Agent of an existing browser (e.g. "Mozilla/5.0"). Maybe the website doesn't respond to requests without a 'real' user agent (I've seen this a few times).

Thanks, although it still doesnt work for me. I tried both with "Mozilla/5.0" and "Opera/9.60 (Windows NT 5.1; U; de) Presto/2.1.1"(got from this site) as User-Agent header, but the website seems not to care too much about this.
Here is the script I use everytime when I create a new http request:
var rq;
rq=httprequest_create();
//httprequest_set_request_header(rq, "User-Agent", "Mozilla/5.0", true);
httprequest_set_request_header(rq, "User-Agent", "Opera/9.60 (Windows NT 5.1; U; de) Presto/2.1.1", true);  
httprequest_connect(rq,argument0,0);
return rq;
Can something else be revealing that the game is not a browser?
  • 0

suno li walo
ale li pona


#19 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 16 June 2011 - 06:35 PM

I've added SHA-1, and I've also added an example for the HMAC scripts.

@locohost: Okay, try this one:
http://www.mediafire...adwi5lxch97dum9
I have no idea why the first one doesn't work though.

@regular: There are a lot of possibilities, including:
- 'Referer' header (url of the previous page that was visited)
- 'Cookie' header
- 'Accept-Encoding' header
And many more. You could try a Firefox plugin like HttpFox to find out what headers Firefox is sending, and copy those headers to your program (except the Connection and Keep-Alive headers, those can't be used with this DLL).

If that doesn't work, can you tell me the URL of the website?
  • 1
Posted Image

#20 locohost

locohost

    GMC Member

  • GMC Member
  • 459 posts
  • Version:GM:Studio

Posted 16 June 2011 - 06:49 PM

@Maarten: I went to your website and got it from there. Not sure what's up with the link though. Thanks :)
  • 0

#21 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • GMC Elder
  • 9603 posts
  • Version:GM:Studio

Posted 17 June 2011 - 01:22 AM

Thank you for adding in SHA1/HMAC scripts. I'm a little confused, though. I thought that if the length of the message was greater than 64 bytes (the SHA1 hash length), it was supposed to be SHA1'd before the rest of the HMAC algorithm. Yet the way you have it, without that, matches up with an online HMAC-SHA1 calculator. Before I spend time learning how to work with OAuth, I kind of wonder whether it's supposed to hash-if-too-long or not?

-IMP ;) :)
  • 0

:GM123: Are you an artist who likes creating original creature designs? Maybe you can help out with Elementa here! Give it a look; you might like the idea :)

:bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny:


#22 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 3578 posts
  • Version:GM:Studio

Posted 17 June 2011 - 03:53 AM

Thanks for adding SHA-1, really nice indeed.. altrough i have no idea on how it works internally..

*runs off to read some wiki articles*
  • 0

@MEtchegaray7

gplussignature.png

May this signature be frozen on the old GMC until the end of times. Or YoYo takes it down.


#23 regular

regular

    GMC Member

  • New Member
  • 399 posts

Posted 17 June 2011 - 10:19 AM

I've added SHA-1, and I've also added an example for the HMAC scripts.

@locohost: Okay, try this one:
http://www.mediafire...adwi5lxch97dum9
I have no idea why the first one doesn't work though.

@regular: There are a lot of possibilities, including:
- 'Referer' header (url of the previous page that was visited)
- 'Cookie' header
- 'Accept-Encoding' header
And many more. You could try a Firefox plugin like HttpFox to find out what headers Firefox is sending, and copy those headers to your program (except the Connection and Keep-Alive headers, those can't be used with this DLL).

If that doesn't work, can you tell me the URL of the website?

I inserted some more headers and it works now.
  • 0

suno li walo
ale li pona


#24 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 17 June 2011 - 11:01 PM

Thank you for adding in SHA1/HMAC scripts. I'm a little confused, though. I thought that if the length of the message was greater than 64 bytes (the SHA1 hash length), it was supposed to be SHA1'd before the rest of the HMAC algorithm. Yet the way you have it, without that, matches up with an online HMAC-SHA1 calculator. Before I spend time learning how to work with OAuth, I kind of wonder whether it's supposed to hash-if-too-long or not?

-IMP ;) :)

I just did what the wikipedia article said, and it didn't say anything about the length of the message. I just tested it with a 616-byte message and the result is the same as the result of PHP's hash_hmac function, so I think it's correct :).

Edited by Maarten Baert, 17 June 2011 - 11:01 PM.

  • 0
Posted Image

#25 orange451

orange451

    GMC Member

  • GMC Member
  • 1411 posts
  • Version:GM8.1

Posted 18 June 2011 - 04:08 PM

Is there a way to execute a file on a website as if a user were viewing in their browser?
like if I have a php file on my site that ads information to a db, can I execute the file with this?

such as:
test.php?ID=1&user=orange451&lvl=4
my test.php would request the id, user, and lvl.
  • 0

bC14QqN.pngNrTFeil.png


#26 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • GMC Elder
  • 9603 posts
  • Version:GM:Studio

Posted 19 June 2011 - 05:52 PM

I'm sorry, I was thinking of the key and not the message. The Wikipedia article says:

K be a secret key padded to the right with extra zeros to the input block size of the hash function, or the hash of the original key if it's longer than that block size


Although, if I got the message and key mixed up for that, perhaps I did so as well when I tried my own HMAC? :P . Anyway, glad to see it all works out, so I'll be trying to access Twitter at some point (my previous Twitter client, TweetyMotion, worked perfectly for less than 2 months before Twitter switched over to OAuth).

-IMP ;):)

*EDIT* @orange451: Just send a request to it. Your page doesn't know (or care, really) if the request is coming from a browser or not. It'll output the same thing.

Edited by IceMetalPunk, 19 June 2011 - 05:53 PM.

  • 0

:GM123: Are you an artist who likes creating original creature designs? Maybe you can help out with Elementa here! Give it a look; you might like the idea :)

:bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny: :excl: :bunny:


#27 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 19 June 2011 - 11:52 PM

You're right, I missed that part. I've changed the scripts now.
  • 0
Posted Image

#28 Dan The Man

Dan The Man

    Super Smash Master

  • GMC Member
  • 534 posts

Posted 20 June 2011 - 06:34 PM

Hey guys,

So would this be the correct DLL for me if I simply want to access an address like:

http:///www.supersmashland.com/scores.php?action=submit&score=3400&type=something

but not have it open a browser simply just access the url so the php would save the score? Or would I need to use something like 39dll? Or could I even do something like that without a DLL?

Thanks,
Dan
  • 0

smashland-siggy.gif


#29 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 20 June 2011 - 08:53 PM

Yes, it will work. The website doesn't care whether the request was sent by a browser or another program.

You can open a browser without a DLL, but if you don't want that you have to use a DLL like this one.
  • 0
Posted Image

#30 Manuel777

Manuel777

    InvaderGames

  • GMC Member
  • 3578 posts
  • Version:GM:Studio

Posted 22 June 2011 - 03:22 AM

Hey Maarten, when trying to compile with Visual C++ 2008 Express, it cant find "stdint.h".. wich compiler you used? or even better, is there anywhere i can find the missing files? (they where many..)
  • 0

@MEtchegaray7

gplussignature.png

May this signature be frozen on the old GMC until the end of times. Or YoYo takes it down.


#31 FredFredrickson

FredFredrickson

    Artist

  • Global Moderators
  • 9225 posts
  • Version:GM:Studio

Posted 22 June 2011 - 05:31 AM

This seems to be a great DLL - I'm enjoying testing it, at any rate. :)

One problem though: I am having trouble getting POST variables to work. I've followed the documentation and set the third argument in the httprequest_connect script to true, and set up a few httprequest_set_post_parameter()'s, but my php file seems to not be able to read them, using $_REQUEST or $_POST. When I use $_REQUEST to get the variables and then just put them in the URL (like file.php?a=1&b=2) it reads them just fine, and I am getting the file back both ways, so I know the request is going through and coming back alright.

Anyone else having this problem? Any way to fix it?
  • 0

#32 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 22 June 2011 - 05:02 PM

Hey Maarten, when trying to compile with Visual C++ 2008 Express, it cant find "stdint.h".. wich compiler you used? or even better, is there anywhere i can find the missing files? (they where many..)

stdint.h is a standard header file, it should be there. Maybe your compiler isn't installed properly? What other files were missing?

You will also need ws2_32.lib, which is also included with VC++. You have to add it to the list of libraries in the build options window.

This seems to be a great DLL - I'm enjoying testing it, at any rate. :)

One problem though: I am having trouble getting POST variables to work. I've followed the documentation and set the third argument in the httprequest_connect script to true, and set up a few httprequest_set_post_parameter()'s, but my php file seems to not be able to read them, using $_REQUEST or $_POST. When I use $_REQUEST to get the variables and then just put them in the URL (like file.php?a=1&b=2) it reads them just fine, and I am getting the file back both ways, so I know the request is going through and coming back alright.

Anyone else having this problem? Any way to fix it?

I just tested it with this file:
http://andere.maarte...be/postecho.php
It still works, so I think there's something wrong with your code. Are you sure you're calling httprequest_set_post_parameter before httprequest_connect?
  • 0
Posted Image

#33 FredFredrickson

FredFredrickson

    Artist

  • Global Moderators
  • 9225 posts
  • Version:GM:Studio

Posted 22 June 2011 - 05:25 PM

I'm at work now, so I don't have access to my Game Maker files, but I'm almost certain that I had everything in the right order. I'll try it out on the site you provided when I get back though - maybe I've just got something twisted up in my PHP file. That is doubtful though, since it works just fine with $_GET and $_REQUEST, with the vars in the URL.

I appreciate the help though. Is there any other reason you can think of for why it might not be working?

Well, the site you posted seems to work just fine... funny how mine is not. I'm assuming your PHP script for receiving and showing the data is small; would you mind posting it here so I could drop a copy on my website and see if it works there (to make sure it's not just some quirk with my host)? Thanks Maarten. :)
  • 0

#34 FredFredrickson

FredFredrickson

    Artist

  • Global Moderators
  • 9225 posts
  • Version:GM:Studio

Posted 23 June 2011 - 02:11 AM

Sorry for the double post, but I think I figured out what the problem is.

Here's the code I'm using in GML:
var httprequest, st;
httprequest = httprequest_create();
httprequest_set_post_parameter(httprequest, "a", "3");
httprequest_connect(httprequest, "http://website.com/file.php?b=3", true);
...

And here's my PHP file:
<?php
print '<pre>';
print_r($_REQUEST);
print '</pre>';
?>

When I run this, I get the following response back:

<pre>
Array
(
b=> 3
3=> 3
)
</pre>


So it would seem that instead of passing my variable name "a" as the name of the POST var, it's using the value for both. Perhaps just a simple typo on your part? :)

I realize the source comes with the program and I could try fixing it myself, but I'm not very useful when it comes to editing / writing C++, so I probably wouldn't know where to begin. Assuming that this is just a simple variable mix-up in the code.
  • 0

#35 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 23 June 2011 - 06:57 PM

I've tested it again with your code, but I just get the expected result:
<pre>Get:
Array
(
    [b] =&gt; 3
)
Post:
Array
(
    [a] =&gt; 3
)
Files:
Array
(
)
Request:
Array
(
    [b] =&gt; 3
    [a] =&gt; 3
)
</pre>
Source:
<?php

ob_start();

echo "Get:\r\n";
print_r($_GET);
echo "Post:\r\n";
print_r($_POST);
echo "Files:\r\n";
print_r($_FILES);
echo "Request:\r\n";
print_r($_REQUEST);

$data = ob_get_clean();
echo "<pre>".htmlspecialchars($data)."</pre>";

?>
So it looks like it's some server-side setting/feature/bug. I've double-checked all relevant functions but I can't find anything that could explain this (unless std::string is buggy, but that's unlikely).

What do you get when you submit a normal HTML form?
<form method="post" action="file.php?b=3">
<input type="hidden" name="a" value="b">
<input type="submit">
</form>

Edited by Maarten Baert, 23 June 2011 - 07:04 PM.

  • 0
Posted Image

#36 FredFredrickson

FredFredrickson

    Artist

  • Global Moderators
  • 9225 posts
  • Version:GM:Studio

Posted 23 June 2011 - 07:41 PM

I altered your code slightly to give each value a text name and a numeric value:
<form method="post" action="file.php?b=3">
<input type="hidden" name="a" value="5">
<input type="submit">
</form>

This simple web form returns the correct result:

Array
(
[b] => 3
[a] => 5
)


It also returned a few cookie values from the server, which I snipped. They did not include anything that would have set "a" to a different value (like I showed above), and would not even be accessible to Game Maker since it's not pulling the page through my browser. The vars were from a cookie for the forum I have set up on a different part of the website.

So I am at a loss here. The script returns the correct results when I access it with a web form, but when I use this DLL in Game Maker (and then, only when using POST), it does not. Would it be helpful to provide a URL where you can access this file for testing? Do you have any other web space you've tested this on? Is there a way to check the headers or the raw request / response for these pages, to make sure that the POST data is correct when coming from the DLL?

Thanks for your help! I'd really like to continue testing this DLL for some upcoming projects of mine. POST isn't an absolute requirement, but I'd like to try using it in place of URL encoded vars, so it could work well for me if we can figure out what the problem is!
  • 0

#37 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 23 June 2011 - 09:41 PM

That's weird. The URL would be helpful, I want to try to reproduce it on my computer so I can see what's happening.

You can analyze the packets with Wireshark. I just tried it, but the request looks fine.

EDIT: I tried sending a few post requests to other sites, and all of them worked. I think it's either a server problem, or a weird bug in your code. Could you also post the exact code that causes the problem?

Edited by Maarten Baert, 23 June 2011 - 10:12 PM.

  • 0
Posted Image

#38 FredFredrickson

FredFredrickson

    Artist

  • Global Moderators
  • 9225 posts
  • Version:GM:Studio

Posted 23 June 2011 - 10:12 PM

I've PM'd you the URL. Hope that helps get to the bottom of this! :)

Edit: Oh, and I will grab the code from my test game and post it here when I get home.

Edit again: I'm going to PM you the source files.
  • 0

#39 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 24 June 2011 - 08:47 PM

I think I've found it. It happens both with your URL and my own URL, so it's not a server-side issue. The bug only occurs in GM8.1, not in any other version I've tested. This explains why I couldn't reproduce it in my GMK - I was using GM8 (I always use GM8 for DLLs and examples for compatibility). It looks like a bug in GM8.1 and it has already been reported (twice, actually):
http://bugs.yoyogame...iew.php?id=1215
http://bugs.yoyogame...iew.php?id=1243

I could rewrite all functions so they use just one string argument, but that would be very inconvenient and just silly for GM8 users. If you still have GM8 you could use it instead (temporarily, hopefully).
  • 0
Posted Image

#40 FredFredrickson

FredFredrickson

    Artist

  • Global Moderators
  • 9225 posts
  • Version:GM:Studio

Posted 28 June 2011 - 08:45 PM

Indeed, that seems to have been the problem. The newest version of Game Maker (you have to uninstall and download the newest version) seems to fix it! :)

Edit 1: Okay, nevermind - scratch that. It still seems to be broken in 8.1. When I pass multiple post variables to the DLL, anything that is numeric gets the number added as both the key and the value. Time to head back to the bug report board. *sigh*

Edit 2: In case anyone has more to add, or is looking for the bug report I've been using, it's here: http://bugs.yoyogame...iew.php?id=1243

You'll need to be logged into the bug tracker to see it. Also, it seems to be assigned to Russell at this point, so hopefully that means it'll be addressed soon. :)
  • 0

#41 Buff-Robotix

Buff-Robotix

    Who Took My Pants!?!

  • GMC Member
  • 329 posts
  • Version:Unknown

Posted 24 August 2011 - 04:19 AM

Hello.
I'm quite interested in your really cool http request functions especially being able to set post parameters, that's pretty awesome. Now I understand how to do text box forms pretty well but I was wondering if you would be able to check radio boxes? to my understanding the display text is the value and they have another variable called checked and it has to be set to "checked." I'm not sure how to do this with your DLL. Any help is appreciated!

ThanX
RobotiX
  • 0

#42 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 24 August 2011 - 09:49 AM

Radio boxes all have the same name but a different value. You should look at the HTML source of the web page to find the correct values. For example:
<input type="radio" name="test" value="1"> Option 1<br>
<input type="radio" name="test" value="2"> Option 2<br>
<input type="radio" name="test" value="3"> Option 3<br>
So if you want to select option 2, you should do this:
httprequest_set_post_parameter(request, "test", "1");

  • 0
Posted Image

#43 Buff-Robotix

Buff-Robotix

    Who Took My Pants!?!

  • GMC Member
  • 329 posts
  • Version:Unknown

Posted 25 August 2011 - 05:13 AM

That's what I thought and I am still unable to make it work, it might be something wrong with other parts of my code... Someone wrote a script for sending txt messages using your dll by using http://wwww.txtdrop.com/ Its pretty simple in concept and easy to use. I thought I would try the same with http://www.pixdrop.com/ so I could send pictures to my cell phone. This would have a variety of applications but PixDrop has radio buttons and a file upload form so its a little less straight forward. But I suppose you are correct, the radio form is
<input name="group1" value="Verizon" type="radio">
It must be my attempt at the file upload form... Which I'm not sure how to take care of.

ThanX
RobotiX
  • 0

#44 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 26 August 2011 - 08:29 PM

Can you post the code you're using now?
  • 0
Posted Image

#45 Buff-Robotix

Buff-Robotix

    Who Took My Pants!?!

  • GMC Member
  • 329 posts
  • Version:Unknown

Posted 27 August 2011 - 12:59 AM

Sure thing.
Here is the code for TxtDrop, works flawlessly.
//argument0: (string) 10 Digit Phone Number
//argument1: (string) Message
//argument2: (string) Return E-mail address
txt_req=httprequest_create();
httprequest_set_post_parameter(txt_req, "submit", "Send");
httprequest_set_post_parameter(txt_req, "submitted", "1");
httprequest_set_post_parameter(txt_req, "body", argument1);
num=argument0;
num=string_digits(num);
area_code=string_copy(num, 1, 3);
exchange=string_copy(num, 4, 3);
num=string_copy(num, 7, 4);
httprequest_set_post_parameter(txt_req, "npa", area_code);
httprequest_set_post_parameter(txt_req, "exchange", exchange);
httprequest_set_post_parameter(txt_req, "number", num);
httprequest_set_post_parameter(txt_req, "emailfrom", argument2);
httprequest_connect(txt_req, "http://www.txtdrop.com/",1);
while (httprequest_get_state(txt_req)>0 && httprequest_get_state(txt_req)<4)
{
    httprequest_update(txt_req);
}
httprequest_destroy(txt_req);

And here is my attempt at PixDrop.
//argument0 (string) 10 Digit Phone Number
//argument1 (string) Carrier: "Verizon", "At&t", "Sprint", or "T-Mobile"
//argument2 (string) Filename
pix_req=httprequest_create();
httprequest_set_post_parameter(pix_req, "genit", "Send Your Picture Message");
httprequest_set_post_parameter(pix_req, "group1", argument1);
httprequest_set_post_parameter(pix_req, "userfile", argument2);
num=argument0;
num=string_digits(num);
httprequest_set_post_parameter(pix_req, "to", num);
httprequest_connect(pix_req, "http://www.pixdrop.com/",1);
while (httprequest_get_state(pix_req)>0 && httprequest_get_state(pix_req)<4)
{
    httprequest_update(pix_req);
}
httprequest_destroy(pix_req);

I think it might be because there is a file being uploaded I need to use a buffer but I don't know the uploaded file name and I'm not sure how to use the buffers.
Thanks for taking the time to figure this out.

RobotiX
  • 0

#46 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 28 August 2011 - 02:28 PM

You can use httprequest_set_post_parameter_file to upload files. Some of the carrier values were also wrong, the correct values are
"Verizon", "AT&T", "Sprint", "Tmobile"

I think this should work:
//argument0 (string) 10 Digit Phone Number
//argument1 (string) Carrier: "Verizon", "AT&T", "Sprint", or "Tmobile"
//argument2 (string) Filename

var pix_req, num, b, st;

b = buffer_create();
if (!buffer_read_from_file(b, argument2)) {
    buffer_destroy(b);
    return false; // file does not exist
}

pix_req=httprequest_create();

num=string_digits(argument0);
httprequest_set_post_parameter(pix_req, "group1", argument1);
httprequest_set_post_parameter(pix_req, "to", num);
httprequest_set_post_parameter(pix_req, "MAX_FILE_SIZE", 200000);
httprequest_set_post_parameter(pix_req, "genit", "Send Your Picture Message");

httprequest_set_post_parameter_file(pix_req, "userfile", filename_name(argument2), b);
buffer_destroy(b);

httprequest_connect(pix_req, "http://www.pixdrop.com/", 1);
while (true) {
    httprequest_update(pix_req);
    st = httprequest_get_state(pix_req);
    if (st=4 or st=5) {
        break;
    }
    sleep(10);
}

httprequest_destroy(pix_req);
return (st=4);

  • 0
Posted Image

#47 Buff-Robotix

Buff-Robotix

    Who Took My Pants!?!

  • GMC Member
  • 329 posts
  • Version:Unknown

Posted 01 September 2011 - 03:51 AM

PixDrop was really slow yesterday, better today but, sadly, your code doesn't work :(
It looked so nice too...
  • 0

#48 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 01 September 2011 - 12:40 PM

Did you try to read the message body to find out what pixdrop says?

Also, are you sure the phone number should be entered without the '-' characters?

Recipients mobile number: (i.e 212-867-5309)

Maybe it will work if you try it without string_digits?
  • 0
Posted Image

#49 Dom83

Dom83

    GMC Member

  • GMC Member
  • 138 posts

Posted 10 September 2011 - 07:10 PM

At last I found a download dll that I really like ! :)

I'd like to use it with a website where I need to get logged in before accessing... how can I do that with this dll ? Do you have an idea ?
  • 0

#50 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 11 September 2011 - 11:32 AM

At last I found a download dll that I really like ! :)

I'd like to use it with a website where I need to get logged in before accessing... how can I do that with this dll ? Do you have an idea ?

The easiest way to find out how this works is to install a browser plugin that can log the HTTP requests. If you're using Firefox you can try 'HttpFox'. Tell the plugin to log the HTTP requests, and then log in to the website as usual and do whatever action you want the program to perform later. Afterwards you can read the HTTP requests log to find out what parameters the browser is sending. For every page, you should find out:
- what url the browser connects to (easy)
- what GET and POST parameters are sent by the browser
- what cookies are sent by the browser
Once you know all this, you can use the DLL to imitate the requests.
  • 0
Posted Image