greacius Posted March 19, 2010 Share Posted March 19, 2010 Hi, I'm making a resource that will register all stats of a server and sends it to a webserver. The only problem is: How to make a web request? If I use callRemote the webserver responds with cURL ERROR 22 but if I try to use it in my web browser, I don't get any problems. Thanks for your help! Mart P.S. Sorry for my bad english. Link to comment
50p Posted March 19, 2010 Share Posted March 19, 2010 I've never had that problem. CURLE_HTTP_RETURNED_ERROR (22)This is returned if CURLOPT_FAILONERROR is set TRUE and the HTTP server returns an error code that is >= 400. This means, your call fails because server returns error >=400 (page not found, timeout, access denied, etc.) Either your MTA server can't access the website or your site is down but you said you can access it from browser, so the site is not down, this is weird. Make sure the site you're sending request to in callRemote is valid and that your resource can use callRemote function (acl.xml). Link to comment
greacius Posted March 19, 2010 Author Share Posted March 19, 2010 (edited) it is added in the admin acl and there isnt any acces denied error..... someone has the same problem? and what do you mean with valid? Its a website and it isnt special used for mta.. here is my code: function CallBack(CallBackInfo,ERRORCODE) if (CallBackInfo ~= "ERROR") then outputDebugString("Function succesfully called with report: " ..CallBackInfo.. " and code: " ..ERRORCODE) else outputDebugString("ERROR on sending report to MTAStats Server with error: " ..CallBackInfo.. " and code: " ..ERRORCODE) end end function NewPlayer() player = source if (player) then playername = getPlayerName(player) if (playername ~= "Player") then callRemote("URL STRIPPED" ..playername,CallBack) end end end addEventHandler("onPlayerJoin",getRootElement(),NewPlayer) function OldPlayer() player = source if (player) then playername = getPlayerName(player) if (playername ~= "Player") then callRemote("URL STRIPPED" ..playername,CallBack) end end end addEventHandler("onPlayerQuit",getRootElement(),OldPlayer) Edited July 28, 2011 by Guest Link to comment
greacius Posted March 19, 2010 Author Share Posted March 19, 2010 I found the problem: It cannot use the GET variable... now the problem is: how to use any get variable? Link to comment
lil Toady Posted March 19, 2010 Share Posted March 19, 2010 https://wiki.multitheftauto.com/wiki/CallRemote https://wiki.multitheftauto.com/wiki/PHP_SDK those pages will help you understand how you pass data with callRemote Link to comment
greacius Posted March 20, 2010 Author Share Posted March 20, 2010 I found that callRemote only supports POST variables but what are the names of them? And about the PHP SDK: I don't use PHP.. as you can see on the URL. Thanks Link to comment
greacius Posted March 28, 2010 Author Share Posted March 28, 2010 I now have a new question: what arethe names of the post arguments? Thanks! Link to comment
Aibo Posted March 28, 2010 Share Posted March 28, 2010 there's no names, as i recall, it sends arguments as an ordered JSON array: You will need your own page - callRemote doesn't use a standard way of making requests - it sends the arguments as the JSON-encoded body of a POST request, which isn't a conventional thing to do - but provides more flexibility than a GET request could. https://forum.multitheftauto.com/viewtop ... 35#p303635 Link to comment
greacius Posted March 29, 2010 Author Share Posted March 29, 2010 the problem is: I am making an ASP.NET Page and how do you use JSON with ASP.NET? Link to comment
Aibo Posted March 29, 2010 Share Posted March 29, 2010 http://lmgtfy.com/?q=how+do+you+use+JSO ... ASP.NET%3F Link to comment
eAi Posted March 29, 2010 Share Posted March 29, 2010 It should be entirely possible and pretty easy to get this working with ASP.NET. If you do, please release your source so others can use it! Link to comment
greacius Posted March 29, 2010 Author Share Posted March 29, 2010 thanks for the stupidity google but i don't know if you noticed: thats all about ASP.NET to Java and I want MTA -> ASP.NET... so does anyone know an option? Thanks! Link to comment
lil Toady Posted March 30, 2010 Share Posted March 30, 2010 Probably would make sense to download the mta php sdk, check what it does and replicate in asp Link to comment
Aibo Posted March 31, 2010 Share Posted March 31, 2010 thanks for the stupidity google but i don't know if you noticed: thats all about ASP.NET to Java and I want MTA -> ASP.NET... so does anyone know an option?Thanks! you're not even trying. dont you? and i bet JSON is the same everywhere. you need to (basically the stuff PHP SDK does with the input, except convertToObjects()): 1. get JSON from the input stream. in php: file_get_contents('php://input'); 2. decode JSON. in php: json_decode(file_get_contents('php://input')); and since you're making the page in ASP.NET you should know how to do this. and if you don't know, this has nothing to do with MTA or Lua scripting, so you should ask on relevant forums. *) Link to comment
greacius Posted March 31, 2010 Author Share Posted March 31, 2010 well... JSON is the same everywhere but ASP.NET handles it using an other method.. and since you can't script ASP.NET (VB.NET or C#.NET) you don't know what i mean. I'm going to find out how to handle it and I'm getting some ideas:) Thanks for the help! Link to comment
greacius Posted March 31, 2010 Author Share Posted March 31, 2010 I found the way how to handle it! Here is my ASP.NET Test code: Sub WebLoad(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Init Dim variable As String For Each variable In Request.Form Response.Write(variable & " ") Try Dim openfile As System.IO.FileStream = System.IO.File.Create("C:\MTAStats\development.txt") openfile.Close() Catch ex As Exception End Try System.IO.File.AppendAllText("C:\MTAStats\development.txt", "\r\n" & variable) Next Request.SaveAs("C:\MTAStats\requestinfo.txt", False) For Each Header As String In Request.Form.Keys Dim openfile2 As System.IO.FileStream = System.IO.File.Create("C:\MTAStats\requestheaders.txt") openfile2.Close() System.IO.File.AppendAllText("C:\MTAStats\requestheaders.txt", Header & " - ") Next Dim openfile3 As System.IO.FileStream = System.IO.File.Create("C:\MTAStats\requestjson.txt") openfile3.Close() System.IO.File.AppendAllText("C:\MTAStats\requestjson.txt", decodeJSON(System.IO.File.ReadAllText("C:\MTAStats\requestinfo.txt"))) End Sub Function decodeJSON(ByVal JSONCode As String) As String Dim JSONDencrypter As New JavaScriptSerializer Dim JSONReturnObject As Array = JSONDencrypter.DeserializeObject(JSONCode) Dim JSONReturn As String = JSONReturnObject(0) Return JSONReturn End Function Thanks for all help!! Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now