Solved CSharp: WebRequest

Discussion in 'Rust Development' started by iDyn, Mar 9, 2015.

  1. Having troubles triggering a basic Get request and not entirely sure if I'm doing something wrong or the extension isn't yet compatible. I'm wanting to send a request to the URL and read the response.

    These code snippets compile fine in the plugin and produce no error when being called - they simply don't output anything. I found a thread after searching and tried variations of it: http://oxidemod.org/threads/equivalent-to-webclient-downloadstring-in-c.6801/#post-66690

    Code:
    WebRequests.GetWebrequest pWeb = new WebRequests.GetWebrequest("http://www.google.com", (code, response) => Puts("{0}, {1}", code, response), this);
    pWeb.Process();========var pWeb = new WebRequests.GetWebrequest("http://www.google.com", (code, response) => Puts("{0}: {1}", code, response), this);     
    pWeb.Process();========WebRequests pWeb = new WebRequests();
    pWeb.EnqueueGet("http://www.google.com", (code, response) => Puts("{0}, {1}", code, response), this);
    Using Google as an example - doesn't work on any specified URL. The code is being ported from a LUA plugin where it worked okay (via EnqueueGet).
     
  2. don't know will it work on oxide or not, but u can try:

    Code:
    using System.Net;
    using System.IO;
    ...
    private static string GetRequest(string url)
    {
        WebResponse response = WebRequest.Create(url).GetResponse();
        StreamReader reader = new StreamReader(response.GetResponseStream());
        string content = reader.ReadToEnd();
        reader.Close();
        response.Close();
        return content;
    }void SomeFunction()
    {
        string req = GetRequest("http://oxidemod.org");
    }
    
    [DOUBLEPOST=1425930230][/DOUBLEPOST]Also u can use Unity: http://docs.unity3d.com/ScriptReference/WWW.html
     
  3. Wulf

    Wulf Community Admin

  4. Wulf

    Wulf Community Admin

  5. Wulf

    Wulf Community Admin

    You'd have to use it essentially the same way I believe. I don't know of any examples though. @bawNg is wanting to wrap it for C# plugins eventually as well.
     
  6. just a small example:
    Code:
    Interface.GetMod().GetLibrary<WebRequests>("WebRequests").EnqueueGet("http://www.google.com", (code, response) => Puts("{0}, {1}", code, response), this);
    
     
  7. Wulf

    Wulf Community Admin

    Thanks, helpful as always!
     
  8. Perfect - worked fine! Didn't think to call it like that but it makes sense.

    Get that put into the CSharp examples! :cool:
     
  9. I did it, but the answer comes in the console all the code page. And in response to convey not all code pages such as "ok"