Hello again
i tryed using the Example Snippet in the Doc for POST-Request (so i customized nothing, in the first place)
but its not working
Code:[Oxide] 21:30 [Error] Failed to call hook 'PostRequest' on plugin 'MyPlugin v0.1 .0' (InvalidCastException: Cannot cast from source type to destination type.) [Oxide] 21:30 [Debug] at Oxide.Plugins.MyPlugin.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00000] in <filename unknown>: 0 at Oxide.Plugins.CSharpPlugin.InvokeMethod (System.Reflection.MethodInfo metho d, 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 at Oxide.Core.Plugins.Plugin.CallHook (System.String hookname, System.Object[] args) [0x00000] in <filename unknown>:0
Solved POST webrequest not working (wrong command parameter)
Discussion in 'Hurtworld Development' started by Glumi Chan, May 12, 2016.
-
Wulf Community Admin
Please provide the full error, not just the debug info, along with the code you are using exactly.
-
Sorry.
The Error that occurs
Code:[Oxide] 21:30 [Error] Failed to call hook 'PostRequest' on plugin 'MyPlugin v0.1 .0' (InvalidCastException: Cannot cast from source type to destination type.)
Im using this exactly this Code:
Code:[ChatCommand("post")] void PostRequest(IPlayer player, string command, string[] args) { // Set a timeout (in milliseconds) var timeout = 200f; // Set some custom request headers (eg. for HTTP Basic Auth) var headers = new Dictionary<string, string> { { "header", "value" } }; webrequest.EnqueuePost("http://www.google.com/search?q=oxide", "param1=value1¶m2=value2", (code, response) => PostCallback(code, response, player), this, headers, timeout); } void PostCallback(int code, string response, IPlayer player) { if (response == null || code != 200) { hurt.BroadcastChat("Error: - Couldn't get an answer from Google for {player.Nickname}"); return; } hurt.BroadcastChat("Google answered for " + player.Nickname + ": " + response); }
-
Wulf Community Admin
-
Okay:
1. Thank you
2. The API forces me to give a String as a Post Parameter.
What if i want to POST a JSON-Object?
I think simple casting is not a good solution or? -
Wulf Community Admin