HttpRequest doesn´t work

You can talk about ManiaScript for ManiaPlanet here

Moderator: English Moderator

Post Reply
User avatar
Jojo_44
Posts: 485
Joined: 12 Jul 2010, 15:58
Location: Germany->Bavaria
Contact:

HttpRequest doesn´t work

Post by Jojo_44 »

Hey,

I´m trying the new httprequest with Beta 2.0 but my Code doesn´t work:

Code: Select all

		#Include "TextLib" as TextLib
		
		declare CHttpRequest shoutbox;
		
		Void getXMLFromWeb() {
		
			shoutbox = Http.CreateGet("http://localhost/Maniascript/httptest/shoutbox.xml");
			
			while(!shoutbox.IsCompleted) {
				
			}
			
			log(shoutbox.Result);
		}
		
		Void preventBug() {
		
		}
		
		main() {
			
			getXMLFromWeb();
		}
Maniaplanet says that the script consumes too many resources. What´s wrong with my code ?

regards, Jojo
Image
my english sounds very unfriendly but it isn´t ;)
User avatar
m4rcel
Posts: 650
Joined: 15 Jun 2010, 11:12
Contact:

Re: HttpRequest doesn't work

Post by m4rcel »

Same problem for me, I also tried to request some data, but it seems not working in Manialink context.

My script:

Code: Select all

log("Test start");
log("Valid: " ^ Http.IsValidUrl("http://localhost/test/getXML"));
log("Slots: " ^ Http.SlotsAvailable);
declare CHttpRequest Request = Http.CreateGet("http://localhost/test/getXML");
log("Slots: " ^ Http.SlotsAvailable);

declare Integer Next = Now + 1000;
while (True) {
	while (Now < Next) {
		yield;
	}
	
	if (Request.IsCompleted) {
		log("Request Completed, Status: " ^ Request.StatusCode);
		log(Request.Result);
		break;
	} else {
		log("Waiting for Request... Status: " ^ Request.StatusCode);
		Next += 1000;
		yield;
	}		
}
The URL is proofed to be valid, and the slots are decreased with each script call, but yet I was unable to see the request in the network traffic., So the request seems to be actually never started. (Thus, the script of course keeps in the loop printing "Waiting for Request", status is always 0. )
ImageImage
Image
User avatar
steeffeen
Translator
Translator
Posts: 2463
Joined: 14 Oct 2012, 16:22
Location: Germany

Re: HttpRequest doesn´t work

Post by steeffeen »

for me the httprequest worked fine, i tried it during a created multiplayer game (not on a dedicated server)
btw: i suggest

Code: Select all

wait(httprequest.IsCompleted);
for the first test of a http request, so you don't need any loops or something like that
User avatar
m4rcel
Posts: 650
Joined: 15 Jun 2010, 11:12
Contact:

Re: HttpRequest doesn´t work

Post by m4rcel »

steeffeen wrote:for me the httprequest worked fine, i tried it during a created multiplayer game (not on a dedicated server)
btw: i suggest

Code: Select all

wait(httprequest.IsCompleted);
for the first test of a http request, so you don't need any loops or something like that
This was my first test, with the result, that the Browser did not respond anymore (as of never finishing the request). So I replaced it with the loop to have some debug output ;)

And it is good to know that it works for servers, so it may be a bug in the Manialink browser.
ImageImage
Image
User avatar
spaii
Posts: 1075
Joined: 19 Jun 2010, 00:04
Location: Rémy - France
Contact:

Re: HttpRequest doesn´t work

Post by spaii »

Post Reply

Return to “ManiaScript”

Who is online

Users browsing this forum: No registered users and 2 guests