REST webservice GET method with token in external browser

Asked

Viewed 1,210 times

0

I am developing a client who consumes a webservice, all POST methods are ok.

Has a GET method that should return an HTML page for client registration.

in this method, it is necessary to set 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 gets wrong and the buttons don’t work.

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

You can change something in C# to open the page correctly in Webbrowser?

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

UPDATE:

What I’ve already done:

1-

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

Upshot: 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);

Upshot: It works, but the page gets errors, the buttons don’t work CSS is not loaded completely.

3-

I 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)

3 answers

0

There is a nice way to do this in the app itself. Using the web Component, not the native microsoft one, but a third party one. I use the awessomium. Using the free market api, follow the example of the code 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 this above can help you. Because having to go to an external browser, in my view, is a lot of manpower, and this is not the goal of a software.

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

  • Thanks for your attention, then, as it is only an app that will integrate two systems, we prefer not to use external components, usually are several dlls that I have to reference, conseguemente, several dlls that I will have to distribute together with the application. About open in external browser, it’s just a page, quiet. Again, thank you.

0

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

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

https://stackoverflow.com/questions/6293549/setting-authentication-header-for-webbrowser-control-asp-net

https://stackoverflow.com/questions/18035579/how-to-open-a-link-in-webbrowser-control-in-external-browser

  • the web API is third party, probably made in java, I’m making a client in windows form with . net 2.0 (last case only to upgrade the version), consume the method, with token in header is ok within the application, but would like to open it in an external browser due to problems opening the page in the internal browser. Thank you for your attention.

  • Tried to update the. net version and check if you have a newer version of the internal browser in the references ?

  • yes, I even made a window in WPF and tested too, same thing =/. The tricky thing is... make the other company change its software

  • Impracticable it does this, can harm several clients; By external web browser opens normal API page? if opens can try migrating your app to web or mobile?

  • by the external browser, returns a json message, saying that the token has not been informed. Migration is not possible because it is an application to make sales agreement, there is PAF-ECF in the middle and everything else

  • I tried to make a php page, where I pass the parameters by the url, and php would consume the webservice, I can open the page in the browser, but not functional, because it would be in my url, and not where the form should actually work.

  • I updated the question with more information, if you can help me, grateful

Show 2 more comments

0


Solved:

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

It uses an OLE objto that opens internet explorer.

in C# was 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 reference Microsoft Internet Controls by name: Interop.Shdocvw

thanks to all for the cooperation.

Browser other questions tagged

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