Welcome Guest Search | Active Topics | Sign In | Register

post json object to url Options
Pasokh
Posted: Sunday, October 28, 2018 12:52:45 PM
Rank: Newbie
Groups: Member

Joined: 10/28/2018
Posts: 2
I use This code to post to a url in eo browser

Quote:
Request request2 = new Request("http://my.niazerooz.com/member/userpanel/insertmanualupdatequest");
request2.Method = "POST";
request2.Headers.Add("X-Requested-With", "XMLHttpRequest");
webControl1.WebView.LoadRequestAndWait(request2);


it`s work when i want to send text value m but it doesnt work when i want to post josn text to url like
Quote:
{\"orderIds\":[" + item.OrderId + "]}
, what is the best way to implement this in eo.webbrowser?
eo_support
Posted: Sunday, October 28, 2018 5:31:15 PM
Rank: Administration
Groups: Administration

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

You can use built-in .NET WebRequest class to get it working first. That should tell you exactly what you need to set and whether your server is working properly. Once you get that working, you can replace WebRequest with our Request object and it should work.

Thanks
Pasokh
Posted: Monday, October 29, 2018 2:31:48 AM
Rank: Newbie
Groups: Member

Joined: 10/28/2018
Posts: 2
Passing WebRequest Object to webView3.LoadRequestAndWait(WebRequest) is not accepted, and it should be `Request ` object of eo.webbrowser, a request has not some functions like GetRequestStream, Create and some else. do u have sample to post text(like json) to url in eo ?
Quote:

var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://url");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";

using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = "{\"user\":\"test\"," +
"\"password\":\"bla\"}";

streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
}

var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}

eo_support
Posted: Wednesday, October 31, 2018 9:09:36 PM
Rank: Administration
Groups: Administration

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

We are not asking you to pass a WebRequest object to the WebView. We are asking you to use the standard WebRequest to troubleshoot the issue. For example, in the code you posted you would set the WebRequest object's ContentType, so you would need to do the same with our Request object as well.

In order to pass JSON text, you will need to convert the text into binary data, then use a PostDataItem object. The code should be something like this:

Code: C#
//Convert the JSON string into byte array
byte[] data = System.Text.Encoding.UTF8.GetBytes(json);

//Add the byte array into PostData collection
request.PostData.Add(new PostDataItem(data));


Please let us know if this works for you.

Thanks!


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.