webservice REST GET method with token in external browser

0

I'm developing a client that consumes a webservice, all POST methods are ok.

It has a GET method that should return an HTML page for customer registration.

In this method, you need to define the header:

 content-type:"application/json"    
 api-token: {token}

I can call the method and open the page in a webbrowser, but with a lot of CSS and JS errors, the page formatting is wrong and the buttons do not work.

I would like to open this page in an external browser (chrome, firefox, even iexplorer) but when calling the URL, it always returns me that the token was not informed.

Is it possible to change something in C # to open the page correctly in WebBrowser?

Is it possible to open the external browser, passing beyond the URL, the token that should go in the header?

UPDATE:

What I've done:

1 -

 string html = LinkedFarma.CadastrarCliente(); //Retorna o HTML do método GET
 webBrowser1.DocumentText = html;

Result: Does not load CSS and JS (obvious)

2 -

string headers = "api-token: "+Configuracao.Token+"\r\n";
headers += "content-type: application/json";
webBrowser1.Navigate(Configuracao.UrlCadastrarCliente, null, null, headers);

Result: It works, however the page has errors, the buttons do not work the CSS is not loaded completely.

3 -

I have already created a page in PHP, which would receive the Token as a parameter and would make the request redirecting the page, but without success as well. (I ventured into PHP because I have no practice)

    
asked by anonymous 25.04.2017 / 20:17

3 answers

0

Resolved:

The developer of the other company, sent me an example in Delphi and I researched how to do it in C #

It uses an OLE object that opens internet explorer.

In C # it looks like this:

            SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer();
            object Empty = 0;
            object URL = Configuracao.UrlCadastrarCliente;
            IE.Visible = true;

            IE.Navigate2(ref URL, ref Empty, ref Empty, ref Empty, "api-token: "+ Configuracao.Token);

obs. I had to add the Microsoft Internet Controls name: Interop.SHDocVw

Thank you all for the collaboration.

    
27.04.2017 / 22:20
0

I thought it was your API that was having trouble providing its static pages, it would be a simple adjustment;

Now that you have said that it is a desktop application, unfortunately I have never worked with Windows Form, I know you have to open the page in another browser and pass the token, take a look:

link

link

    
25.04.2017 / 22:31
0

There is a cool way to do this in the app itself. Using the web component, not the native Microsoft, but a third party. I share the awessomium . Using free market api, follow the code example I use:

    private void formWebControl_Load(object sender, EventArgs e)
    {
        //navega o site da api com os parametros assim que o formulario abrir
        webLogin.Source = new Uri(https://apisite.com);
    }

    private void Awesomium_Windows_Forms_WebControl_TargetURLChanged(object sender, Awesomium.Core.UrlEventArgs e)
    {
        //evento que ocorre quando a url muda no navegador component, daí é só manipular.
        //logo após chama o evento close;
        Close();
    }

    private void formWebControl_FormClosing(object sender, FormClosingEventArgs e)
    {
        //limpa o component da memória
        webLogin.Dispose();
    }

I think the above can help. Well, having to go to an external browser, in my opinion, is a lot of work, and that's not the purpose of software.

I hope that's it. Anything I can put the full example I use in the free market or even help you.

    
01.05.2017 / 23:48