Welcome Guest Search | Active Topics | Sign In | Register

Post Data Options
Michal Margielewski
Posted: Wednesday, August 27, 2014 11:27:39 AM
Rank: Member
Groups: Member

Joined: 8/27/2014
Posts: 21
Hi,

Now i'm using WebBrowser control and post data to url like this:
webBrowser1.Navigate(m_cTargetPage, null, StrToByteArray(m_cPostData), headers);
http://msdn.microsoft.com/pl-pl/library/ms161355(v=vs.110).aspx

I want send postdata using EO.WebBrowser.WebView and i don't know how...
Is it possible?

Thanks in advance for your help.
eo_support
Posted: Wednesday, August 27, 2014 2:00:23 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,067
Hi,

You would do it with the Request object. It will be something like this:

Code: C#
//Create a new request object
Request request = new Request(url);

//Add one or more post data item
request.PostData.AddValue(name1, value1);
request.PostData.AddValue(name2, value2);
...

//Set method to POST
request.Method = "POST";

//Load it into the WebView
webView1.LoadRequest(request);


Hope this helps. Please feel free to let us know if you still have any more questions.

Thanks!
Michal Margielewski
Posted: Thursday, August 28, 2014 4:24:46 AM
Rank: Member
Groups: Member

Joined: 8/27/2014
Posts: 21
Thanks so much, for your help!
Michal Margielewski
Posted: Thursday, August 28, 2014 4:26:51 AM
Rank: Member
Groups: Member

Joined: 8/27/2014
Posts: 21
Thanks so much, for your help!
Michal Margielewski
Posted: Thursday, August 28, 2014 5:45:25 AM
Rank: Member
Groups: Member

Joined: 8/27/2014
Posts: 21
Hi,

I use your code, but on WebView i dont see content page.
Request request = new Request(m_cTargetPage);
foreach (KeyValuePair<string, string> keyPair in postDataDict)
{
request.PostData.AddValue(keyPair.Key, keyPair.Value);
}
request.Method = "POST";
request.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
webView.LoadRequest(request);

I also use mehtod: LoadRequestAndWait and my app wait and nothing was happend.

When i use this function: webView.LoadUrl(m_cTargetPage) it works correctly but postdata are not send to the server.

So i still have a problem with PostData.
eo_support
Posted: Thursday, August 28, 2014 11:44:19 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,067
Hi,

Your code looks fine to us. Please try to use the standard WebRequest class to do the same and check to see if you can get the correct result HTML that way. If you do get it that way, please try to isolate the problem into a test project and send us the test project including both standard WebRequest code and code that does the post with our WebView. Once we have that we will try to run it here to see if we can spot the difference.

You can find guidelines on submitting test project here:

http://www.essentialobjects.com/forum/test_project.aspx

Thanks!
Michal Margielewski
Posted: Thursday, September 11, 2014 3:55:23 AM
Rank: Member
Groups: Member

Joined: 8/27/2014
Posts: 21
So we find where is a problem.

When we open a window and want to load a POST REQUEST on start Form to WebView there is a problem with EO.WebBrowser control -
but when we send a GET REQUEST everything is ok and page is loaded on form.
i paste a code here and also send my simple application that will show you a my problem.

app.config
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="loadOnStart" value="true"/>
<add key="methodPost" value="true"/>
<add key="startUrl" value="http://httpbin.org/post"/>
</appSettings>
</configuration>

MainForm.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EO.WebBrowser;

namespace MyTest
{
public partial class MainForm : Form
{
WebView view;
public Dictionary<string, string> postDataDict;

public MainForm()
{
InitializeComponent();
//http://httpbin.org/post

EO.WebBrowser.WinForm.WebControl wControl = new EO.WebBrowser.WinForm.WebControl();
wControl.Dock = DockStyle.Fill;

view = new EO.WebBrowser.WebView();
wControl.WebView = view;
this.pView.Controls.Add(wControl);
}

private void MainForm_Load(object sender, EventArgs e)
{
bool loadOnStart = false;
bool isPostMethod = false;

bool.TryParse(System.Configuration.ConfigurationManager.AppSettings["loadOnStart"], out loadOnStart);
bool.TryParse(System.Configuration.ConfigurationManager.AppSettings["methodPost"], out isPostMethod);
string startUrl = System.Configuration.ConfigurationManager.AppSettings["startUrl"];

this.tbUrl.Text = startUrl;
this.chbPost.Checked = isPostMethod;

if (loadOnStart)
this.loadRequest();
}

private void button1_Click(object sender, EventArgs e)
{
this.loadRequest();
}

private void loadRequest()
{
if (chbPost.Checked)
{
postDataDict = new Dictionary<string, string>();
postDataDict.Add("SessionKey", tbSession.Text);
postDataDict.Add("option", tbOption.Text);
postDataDict.Add("Inout", this.tbInOut.Text);

Request request = new Request(this.tbUrl.Text);
foreach (KeyValuePair<string, string> keyPair in postDataDict)
{
request.PostData.AddValue(keyPair.Key, keyPair.Value);
}
request.Method = "POST";
view.LoadRequestAndWait(request);
}
else
view.Url = this.tbUrl.Text;
}

private void tbUrl_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
view.Url = this.tbUrl.Text;
}
}
}

When you start app with loadOnStart = true and methodPost = true - application is waitn and never load view. I suppose that is a probem with EO.WebBrowser or should i use another way to load post request on startup window.
If you start app with loadOnStart = true and methodPost = false you can see a form with html page code.
i also send to support my simple application and then you can debug this.

Will be great if you find a solution for this problem.
Michal Margielewski
Posted: Thursday, September 11, 2014 10:07:45 AM
Rank: Member
Groups: Member

Joined: 8/27/2014
Posts: 21
Maybe you can tell which event tell as that now we can call POST request.
Or after which event you check licenses agreement and WebView is ready to work.

All problems that we have is releated to POST request.
eo_support
Posted: Thursday, September 11, 2014 11:37:59 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,067
Hi,

You can not do a wait load (LoadUrlAndWait or LoadRequestAndWait) in Form_Load handler. Doing so will cause a deadlock and it is unrelated to POST or GET. The deadlock is caused by the following facts:

1. Form_Load is called when the form's window handle is created;
2. Only after Form_Load returns, Windows Forms can continue to create window handle for child controls in the form, at this stage the EO.WebBrowser.WebControl gains a window handle;
3. In order for a load to complete, the WebBrowser must have a window handle first;

So the wait sequence will be:

1. Form_Load waits on LoadUrlAndWait;
2. LoadUrlAndWait waits on WebControl handle ready;
3. WebControl's handle ready waits on Form_Load to return;

This creates a circular waiting sequence thus the deadlock.

To avoid the problem, you can do a LoadRequest instead of LoadRequestAndWait. You can then handle the WebView's LoadComplete event to be notified when the load has completed.

Thanks!
Michal Margielewski
Posted: Thursday, September 11, 2014 1:48:27 PM
Rank: Member
Groups: Member

Joined: 8/27/2014
Posts: 21
So in the same Form code I repleace line:
view.LoadRequestAndWait(request);
this line:
view.LoadRequest(request);
and I see the Form with WebView which is white and with information about trial version of EO.WebBrowser.
So it doesnt help me.

I confrm that when I use on Form start it doesnt work
view.LoadUrlAndWait(this.tbUrl.Text);
but when I use:
view.LoadUrl(this.tbUrl.Text); or view.Url = this.tbUrl.Text; it is working correct.

But loading POST request by function view.LoadRequest(request); on Form Load not works.
eo_support
Posted: Thursday, September 11, 2014 1:54:57 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,067
Hi,

LoadRequest should work. You can check your server log or monitor your network traffic to see if your web server has responded the request properly. If there is no request sent to your web server at all, or if your web server received the request and responded properly but it's not displayed, then you can try to create a test project and send the test project to us. We will investigate as soon as we receive it.

Thanks!
Michal Margielewski
Posted: Thursday, September 11, 2014 2:00:12 PM
Rank: Member
Groups: Member

Joined: 8/27/2014
Posts: 21
I did test a moment ago and it didn't work.
I also use Fidler to see my traffic and my app didnt send any request to page. So there is no traffic from EO.WebBrowser to page when I use LoadRequest() method invoked from Form_Load event.
Michal Margielewski
Posted: Thursday, September 11, 2014 2:35:57 PM
Rank: Member
Groups: Member

Joined: 8/27/2014
Posts: 21
I just send my app to you by email.

Thanks in advance for you help.
eo_support
Posted: Thursday, September 11, 2014 7:59:51 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,067
Thank you for the test project. We have confirmed this is an issue on our side. We should have a new build for you tomorrow that fixes this problem.
Michal Margielewski
Posted: Friday, September 12, 2014 3:17:06 AM
Rank: Member
Groups: Member

Joined: 8/27/2014
Posts: 21
It will be great to solve this problem!

Now we use System.Timers.Timer() and invoke LoadRequestAndWait to load page after 2 seconds when Form_Load was invoked.
This solution works for local installation of our application, but when we open application on Citrix Virutalization System loading application takes much more then 2 seconds, and it isn't stable workaround.

Thanks
eo_support
Posted: Friday, September 12, 2014 12:08:54 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,067
Hi,

We have posted a new build on our download page that should work with LoadRequest inside Form_Load. Please take a look and let us know how it goes.

Thanks!
Michal Margielewski
Posted: Friday, September 12, 2014 1:29:50 PM
Rank: Member
Groups: Member

Joined: 8/27/2014
Posts: 21
Great, it works!

We are satisfied with the solution! It works also on Citrix Systems!

Thanks
eo_support
Posted: Friday, September 12, 2014 2:16:59 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,067
Thanks for confirming the fix. Please feel free to let us know if there is anything else.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.