Webclient downloads a wrong string

Asked

Viewed 176 times

3

I’m trying to create a virtual intelligence system, and hosted the language files on my FTP. These files are from a language I made myself, called SVDB, and hosted on FTP, and when I download in the application the text file it comes with HTML. This is the original file (hosted on FTP):

default {
   wrong: "Desculpe, não entendi";
   language-name: "Português Brasileiro";
   language-code: "PT-BR";
   version: "1.0";
}
replace-strings {
   R0001: "vc|você";
   R0002: "td|tudo";
}
K00001 {
   input: "olá|ola|oi|eae";
   output: "Olá!";
   action-id: "";
}
K00002 {
   input: "tudo bem?|você está bem?";
   output: "Estou bem, obrigado por perguntar.";
   action-id: "";
}

And that’s what the WebClient.DownloadString() low:

inserir a descrição da imagem aqui

It downloads a code totally nothing to do with what I want, and the SVDB parser of the error. That’s the address where the file is hosted:

http://server-advenker32.66ghz.com/Panthon/Server/Langs/pt-br/input.txt

And that’s the code I’m using to download the file:

Public Function GetLanguageServer(ByVal LangCode As String) As MainServer
    Dim v As New WebClient
    Dim s As String = v.DownloadString("http://server-advenker32.66ghz.com/Panthon/Server/Langs/" & LangCode.ToLower & "/input.txt")
    Return TextParser.ResolveServerFromString(s) ' o Parser tenta entender o que foi baixado aqui
End Function

So how do I download the file from a formatting like the original shown above?

Note: The permissions of the hosted file are with code 744 (Public read permissions)

Note: The file is hosted on my uHostAll company FTP.

Note: While trying to access the file by browser, it appears correctly and without any problem.

  • So, how do I emulate this? I was thinking about being able to select the text of the component WebBrowser and copy, because in it appears right, but do not know how could do it, and the worst is that the property DocumentText returns nothing...

  • What API are you talking about, the SVDB?

  • There is something in the middle of the file serving this "content filter". There is no way to do a direct access? Your file is being served by something intermediate. A normal hosting does not do this.

  • 2

    Well, a hosting that puts a JS halfway to me is far from appropriate. Or there’s something you don’t want to comment on, or you’re misusing some resource of hers that has the face of gambiarra :) - If the problem is to circumvent this hosting, the question would be another. As it stands, the problem is the hosting, not your code and not your API.

  • Oh yes, I understood, so I managed to circumvent my own hosting with this answer I just made >:)

2 answers

2


I got by another method, I created a Webbrowser and simply navigated to the file link, this is the method now:

Public Sub GetLanguageServer(ByVal LangCode As String)
    Dim address As String = "http://server-advenker32.66ghz.com/Panthon/Server/Langs/pt-br/input.txt"
    Dim BrowserClient As New WebBrowser
    BrowserClient.Navigate(address)
    AddHandler BrowserClient.DocumentCompleted, Sub() SDK = TextParser.ResolveServerFromString(BrowserClient.Document.Body.InnerText)
End Sub

And it worked, the property Document.Body.InnerText returned the file.

  • I think it’s best to delete the kkk question now

  • I can’t remove a question with a reward ;-;

  • 2

    And you can’t give it to yourself. Leave it at that, just put a warning in the reply, saying your original code was right, but the hosting has a content filter, so you bypassed it with Webbrowser. Jajá I delete my comments. The best thing is that if you explain this in the answer, at least you can give +1 her :D

  • All right, I’ll explain xD

  • 1

    If you want to take it as a basis, what happens is more or less the following: When accessing the file, there is a check on the server for a certain cookie. In case it is not set, instead of the original file being served, a JS page is sent to the client that arrow this cookie using some hashes, and then redirecting the customer to the same address, plus a query string. With the correct cookies, the original file is finally served. Since Webbrowser already does this entire operation for you, as if he were navigating, his solution was to take only the final result.

  • Got it. Thanks for your help.

Show 1 more comment

-1

all right?

By making Webbrowser you will consume more resources than a Webclient, as it is a wrapper of IE and with this will run the entire stack of processing and rendering of internet explorer. To do what you asked, just do.

        //Exemplo gravando em um arquivo físico
        using (var client = new WebClient())
            client.DownloadFile("http://namitec.com.br/teste.txt", @"c:\temp\teste.txt");

        //Exemplo lendo direto para memória
        using (var client = new WebClient())
        {
            using (var stream = new MemoryStream(client.DownloadData("http://namitec.com.br/teste.txt")))
            {
                var text = Encoding.UTF8.GetString(stream.ToArray());
                Console.WriteLine(text);
            }
        }

I took the liberty of putting the example at this address so you can test.

  • This would not work in the case of what was asked, as it depended on cookies set by JS.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.