Jump to content

Web request


greacius

Recommended Posts

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

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

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 by Guest
Link to comment
  • 2 weeks later...
thanks for the stupidity google :lol: 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? :P 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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...