[solved]How do I display an image getting from HTTP GET

Get help using Construct 2

Post » Thu Apr 17, 2014 10:13 am

I want to display an image using a sprite object, and the source of the image is a dynamic url which is a HTTP Get request. The response of the GET is binary datas. Can I use AJAX? or use sprite's Load image from URL to get the image? and how can I handle the response?

p.s. The GET URL is cross domain.

Any one can help me? thanks a lot.

[Solution]
1. Via php script get the remote image binary datas, and save it to local server as jpg or png etc.
2. Use sprite's Load image from URL to display that image.
Last edited by KennyOops on Fri Apr 18, 2014 5:21 am, edited 1 time in total.
B
37
S
4
G
2
Posts: 45
Reputation: 4,007

Post » Thu Apr 17, 2014 10:25 am

You cannot use the AJAX object, only Sprites 'Load image from URL'. You don't need to do anything other than give it the URL, but you must have permission to load images from the server (look up the Access-Control-Allow-Origin HTTP header).
Scirra Founder
B
403
S
238
G
89
Posts: 24,653
Reputation: 196,143

Post » Thu Apr 17, 2014 10:38 am

Thanks @Ashley, I will try it and report the results later.
B
37
S
4
G
2
Posts: 45
Reputation: 4,007

Post » Thu Apr 17, 2014 12:28 pm

Ashley wrote:You cannot use the AJAX object, only Sprites 'Load image from URL'. You don't need to do anything other than give it the URL, but you must have permission to load images from the server (look up the Access-Control-Allow-Origin HTTP header).


@Ashley, I‘ve tried 'Load image from URL', but it didn't work.

I should say that the URL is a servlet, just like this: 'http://aaa.bbb.com/Querylet?Id=anystring', Id is a in-parameter

and the response will like these:
Content-Type: image/jpeg;\r
Content-Length: xx\r
\r


so...'Load image from URL' didn's get anything.
B
37
S
4
G
2
Posts: 45
Reputation: 4,007

Post » Thu Apr 17, 2014 1:01 pm

@KennyOops - yes, you will need to configure Access-Control-Allow-Origin in the server's HTTP response for it to work.
Scirra Founder
B
403
S
238
G
89
Posts: 24,653
Reputation: 196,143

Post » Thu Apr 17, 2014 1:48 pm

@Ashley

woo... I can't configure the server's HTTP response, it's a third-party server....now, it's a serious problem.

what else can I do?
B
37
S
4
G
2
Posts: 45
Reputation: 4,007

Post » Thu Apr 17, 2014 1:55 pm

Nothing. This is how Internet security works: you cannot load resources from third party servers unless they explicitly let you.
Scirra Founder
B
403
S
238
G
89
Posts: 24,653
Reputation: 196,143

Post » Thu Apr 17, 2014 2:01 pm

KennyOops wrote:@Ashley

woo... I can't configure the server's HTTP response, it's a third-party server....now, it's a serious problem.

what else can I do?


It is also illegal to load other websites images/media without consent, AND Hotlinking is a crime.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,728

Post » Fri Apr 18, 2014 1:12 am

Thank you @Ashley @DUTOIT.

The third-party server is a legal charging server, and the image I should get is a verify-code image.

Can I use AJAX plugin requests my php interface to get the image from the third-party? The php interface is deployed on the same server with my game, via php I get and then process the image binary data, echo the response in the end.

If so, anything can process the Ajax.LastData?
B
37
S
4
G
2
Posts: 45
Reputation: 4,007

Post » Fri Apr 18, 2014 1:25 am

You don't load an image from an Ajax request, you just get the URL. You can use standard URL encoding to pass any parameters you need to to the server.

I doubt your third-party is going to let you run XSS anytime ever so as a workaround you can have them fetch the image from your server via a PHP script that gets it from the other server. It may lag a bit more than usual but it should work.
B
9
S
3
Posts: 37
Reputation: 749

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 23 guests