Solved WebRequest geterror

Discussion in 'Rust Development' started by Sauron 2, Jun 19, 2016.

  1. Code:
    using Oxide.Core.Libraries.Covalence;
    using System;
    using System.Collections.Generic;
    using Oxide.Core;
    using Oxide.Core.Plugins;namespace Oxide.Plugins
    {
        [Info("test", "by ", 1.0)]
        [Description("test plugin")]
        class test : RustPlugin
        {
            [ChatCommand("test")]
            void PostRequest(IPlayer player, string command, string[] args)
            {
                webrequest.EnqueuePost("http://www.google.com/search?q=oxide", "param1=value1&param2=value2", (code, response) => PostCallback(code, response, player), this);
            }        void PostCallback(int code, string response, IPlayer player)
            {
                if (response == null || code != 200)
                {
                    Puts($"Error: {code} - Couldn't get an answer from Google for");
                    return;
                }
                Puts("Google answered for : " + response);
            }
        }
    }
    
    Error:
    Code:
    [Oxide] 15:14 [Debug]   at Oxide.Plugins.test.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Plugins.CSharpPlugin.InvokeMethod (HookMethod method, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0
     
  2. Wulf

    Wulf Community Admin

    The error is above the part your posted. Also, your class should start with a capital letter.
     
  3. My class start class should start with a capital letter.

    Here i replace on test

    I do not understand where you posted?
     
    Last edited by a moderator: Jun 19, 2016
  4. Wulf

    Wulf Community Admin

    You have it lowercase (t, should be T):
    5300af1bf4b6c90cb453784cddb584b1.png

    The actual error is in your log, above the DEBUG portion you posted.
     
  5. Even if I change class Test : RustPlugin GET error
     
  6. Wulf

    Wulf Community Admin

    Yes, that was not the cause, just what it should be set to. I still need to see the actual error, not just the debug info.
     
  7. Here please try it for yourself.You will also get the same error I think

    Code:
    using Oxide.Core.Libraries.Covalence;
    using System;
    using System.Collections.Generic;
    using Oxide.Core;
    using Oxide.Core.Plugins;namespace Oxide.Plugins
    {
        [Info("Test", "by ", 1.0)]
        [Description("Test plugin")]
        class test : RustPlugin
        {
            [ChatCommand("Test")]
            void PostRequest(IPlayer player, string command, string[] args)
            {
                webrequest.EnqueuePost("http://www.google.com/search?q=oxide", "param1=value1&param2=value2", (code, response) => PostCallback(code, response, player), this);
            }        void PostCallback(int code, string response, IPlayer player)
            {
                if (response == null || code != 200)
                {
                    Puts($"Error: {code} - Couldn't get an answer from Google for");
                    return;
                }
                Puts("Google answered for : " + response);
            }
        }
    }
     
  8. Wulf

    Wulf Community Admin

    I just need he error, not the code. The error is in he log part hat you didn't show me. Also, you can't use IPlayer in a normal plugin's chat command.
     
  9. and what place to use IPlayer ?.Give an example

    Here you use IPlayer Oxide API for Rust

    İ test on the lua:
    Code:
    PLUGIN.HasConfig    = false
    PLUGIN.Title = "EpicPlugin"
    PLUGIN.Author = "Unknown"
    PLUGIN.Version = V(0, 1, 0)
    PLUGIN.Description = "Makes epic stuff happen"function PLUGIN:Init()
      command.AddConsoleCommand("global.test", self.Plugin, "TestCommand")
    endfunction PLUGIN:OnPlayerChat(arg)
        if not arg then return end
        if not arg.connection then return end
        if not arg.connection.player then return end
        local player = arg.connection.player
        local chat = arg:GetString(0, "text")
        if (chat=="") then return end
        webrequests.EnqueuePost("http://localhost/test.php?key=test","test=1&arg=2", function(code, content)
        if(code == 200) then
            print(content)
        end
        end,self.object)
    end
    test.png
     
    Last edited by a moderator: Jun 20, 2016
  10. Wulf

    Wulf Community Admin

    You didn't read the example correctly, you changed multiple parts of it. Lua works differently.
     
  11. Please provide an example of how to send POST.
     
  12. Wulf

    Wulf Community Admin

    The example is in the API docs: Oxide API for Rust

    The example is for CovalencePlugin, you'd need to adjust accordingly if you want to make a RustPlugin.
     
  13. [Command("post")] ??? this is Command not found console and chat...
    Use [ChatCommand("post")] get error Method Hook...
     
    Last edited by a moderator: Jun 21, 2016
  14. Wulf

    Wulf Community Admin

    The [Command] Attribute is for use with CovalencePlugin, which is what the example uses.
    The [ChatCommand] Attribute is only for RustPlugin and other game-specific ones.

    BasePlayer needs to be used for commands in RustPlugin, IPlayer is for use with CovalencePlugin, you're mixing them up.
     
  15. Ok i understand...Pls give exsample on the C# chat command... How to use BasePlayer...???
     
  16. Wulf

    Wulf Community Admin

    Code:
    using Oxide.Core;
    using Oxide.Core.Libraries;namespace Oxide.Plugins
    {
        [Info("EpicPlugin", "Unknown", 1.0)]
        [Description("This example illustrates how to use a POST Webrequest")]
        class EpicPlugin : RustPlugin
        {
            [ChatCommand("postrequest")]
            void PostRequest(BasePlayer player, string command, string[] args)
            {
                webrequest.EnqueuePost("http://www.google.com/search?q=oxide", "param1=value1&param2=value2", (code, response) => PostCallback(code, response, player), this);
            }        void PostCallback(int code, string response, BasePlayer player)
            {
                if (response == null || code != 200)
                {
                    Puts($"Error: {code} - Couldn't get an answer from Google for {player.displayName}");
                    return;
                }
                Puts("Google answered for " + player.displayName + ": " + response);
            }
        }
    }
    You can also do a console command, but that would be a different attribute as well as arguments. With console commands, everything comes from ConsoleSystem.Arg, which you'd get the play, text, etc. from.
     
  17. Thanks.Please put more examples in docs.oxidemod.org .And that is very little information...

    player.displayName changed player.Name ?
     
    Last edited by a moderator: Jun 22, 2016
  18. Wulf

    Wulf Community Admin

    The Docs are being updated for Covalence, the code I gave you is game-specific.

    player.displayName is from Rust, player.Name is from the Covalence API.
     
  19. On the Visual studio 2015 get error on the BasePlayer??

    And also where you can read all the commands like player.displayName and others...?
    test.png