471,339 Members | 1,280 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,339 software developers and data experts.

Connect To Java Servlet using c# windows forms

I 'm developing a c# (.net 2.0) windows forms application and in this
application i want to connect to a java servlet page (HTTPS) (which is
servlet 2.4 and which may be using Web Based SSO Sun Java System
Access Manager but i 'm not sure), handle session management, get
token, send data using post and get methods etc.
I listened http traffic using Fiddler and sending the same messages
from my application but browser based navigation is working but my
application doesn 't work.

Is there any recommendation ? link ? document etc ?

Jun 27 '08 #1
8 5858
On May 14, 12:47 pm, inpuarg <donteventh...@about.itwrote:
I 'm developing a c# (.net 2.0) windows forms application and in this
application i want to connect to a java servlet page (HTTPS) (which is
servlet 2.4 and which may be using Web Based SSO Sun Java System
Access Manager but i 'm not sure), handle session management, get
token, send data using post and get methods etc.
I listened http traffic using Fiddler and sending the same messages
from my application but browser based navigation is working but my
application doesn 't work.

Is there any recommendation ? link ? document etc ?
What exactly do you mean by "my application doesn't work"? What
exactly happens? You'll need to make sure you accept (and then give
back) appropriate cookies etc, but apart from that it should all be
okay.

Jon
Jun 27 '08 #2
well. after login if i try to browse a page it says session is invalid
etc. (as a custom message in turkish)

i am capturing https traffic using fiddler. i didn 't see any session
or cookie in both request or response header or detail. there is only
a token string. and i am parsing and sending it also. and i am not
doing anything about session or cookie management.

i am sending username and password using post method. and response is
login ok. (also a custom message) i can open another page later. but
at third page it says invalid session. (also a custom message)

how can servlet realize i 'm not using internet explorer. cause if i
use internet explorer everything is fine.

and what do i need to do to simulate that i 'm a web browser etc .
(apart from theese)
HttpWebRequest request = null;
Uri uri = new Uri(url);
request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "POST";
if (this.Referer != "" && this.Referer != null)
{
request.Referer = this.Referer;
}
request.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/xaml+xml,
application/vnd.ms-xpsdocument, application/x-ms-xbap,
application/x-ms-application, application/vnd.ms-excel,
application/vnd.ms-powerpoint, application/msword,
application/x-silverlight, */*";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT
5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30;
InfoPath.2)";
request.KeepAlive = true;
request.ContentType = "application/x-www-form-urlencoded";
request.Headers.Add("Cache-Control", "no-cache");
request.Headers.Add("Accept-Encoding: gzip, deflate");
request.Headers.Add("Accept-Language: en-us,tr-TR;q=0.5");
request.Headers.Add("UA-CPU: x86");
request.ProtocolVersion = HttpVersion.Version11;
request.ContentLength = postData.Length;
request.AllowAutoRedirect = true;

using (Stream writeStream = request.GetRequestStream())
{
Encoding encoding = Encoding.GetEncoding("ISO-8859-9");
byte[] bytes = encoding.GetBytes(postData);
writeStream.Write(bytes, 0, bytes.Length);
}
using (HttpWebResponse response =
(HttpWebResponse)request.GetResponse())
{
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader readStream = new
StreamReader(responseStream, Encoding.GetEncoding("ISO-8859-9")))
{
result = readStream.ReadToEnd();
}
}
}

On Wed, 14 May 2008 04:56:03 -0700 (PDT), "Jon Skeet [C# MVP]"
<sk***@pobox.comwrote:
>On May 14, 12:47 pm, inpuarg <donteventh...@about.itwrote:
>I 'm developing a c# (.net 2.0) windows forms application and in this
application i want to connect to a java servlet page (HTTPS) (which is
servlet 2.4 and which may be using Web Based SSO Sun Java System
Access Manager but i 'm not sure), handle session management, get
token, send data using post and get methods etc.
I listened http traffic using Fiddler and sending the same messages
from my application but browser based navigation is working but my
application doesn 't work.

Is there any recommendation ? link ? document etc ?

What exactly do you mean by "my application doesn't work"? What
exactly happens? You'll need to make sure you accept (and then give
back) appropriate cookies etc, but apart from that it should all be
okay.

Jon
Jun 27 '08 #3
On May 14, 1:19 pm, inpuarg <donteventh...@about.itwrote:
well. after login if i try to browse a page it says session is invalid
etc. (as a custom message in turkish)

i am capturing https traffic using fiddler. i didn 't see any session
or cookie in both request or response header or detail. there is only
a token string. and i am parsing and sending it also. and i am not
doing anything about session or cookie management.
I strongly suspect it's that token which is controlling the session.
How are you determining the URLs to open? It could well be that
they're autogenerated (in the response links) with the session token
on them.

Jon
Jun 27 '08 #4
http://www.fiddler2.com
i am starting to capture http session first by using this tool.
then i 'm starting to browse pages with ie7.
i can clearly see all headers, bodies, response, urls, cookies,
sessions etc. etc.

then i 'M simulating same things withing my application.

i'm just curius about servlet is somehow different etc.
>How are you determining the URLs to open? It could well be that
they're autogenerated (in the response links) with the session token
on them.

Jon
Jun 27 '08 #5
in java servlet documents i saw such things :

public static string TheSessionId() {
HttpSessionState ss = HttpContext.Current.Session;
HttpContext.Current.Session["test"] = "test";
HttpContext.Current.Response.Write(ss.SessionID);
return "ok";
}
------------
public class MyServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();

HttpSession session = request.getSession(true);

out.println("The session ID: " + session.getId() + "<BR>");

i may need that session id.
how can i get that session id from servlet ?

On Wed, 14 May 2008 06:01:03 -0700 (PDT), "Jon Skeet [C# MVP]"
<sk***@pobox.comwrote:
>On May 14, 1:19 pm, inpuarg <donteventh...@about.itwrote:
>well. after login if i try to browse a page it says session is invalid
etc. (as a custom message in turkish)

i am capturing https traffic using fiddler. i didn 't see any session
or cookie in both request or response header or detail. there is only
a token string. and i am parsing and sending it also. and i am not
doing anything about session or cookie management.

I strongly suspect it's that token which is controlling the session.
How are you determining the URLs to open? It could well be that
they're autogenerated (in the response links) with the session token
on them.

Jon
Jun 27 '08 #6
On May 14, 3:02 pm, inpuarg <donteventh...@about.itwrote:
http://www.fiddler2.com
i am starting to capture http session first by using this tool.
then i 'm starting to browse pages with ie7.
i can clearly see all headers, bodies, response, urls, cookies,
sessions etc. etc.

then i 'M simulating same things withing my application.

i'm just curius about servlet is somehow different etc.
It's not - it'll just be part of the response which is used to
identify the session.
Without seeing what the responses look like in detail, it's hard to
say where the session ID will be, but it's *likely* to be in a cookie
or in the URLs exposed by the response.

Jon
Jun 27 '08 #7
On May 14, 3:37 pm, inpuarg <donteventh...@about.itwrote:
in java servlet documents i saw such things :

public static string TheSessionId() {
HttpSessionState ss = HttpContext.Current.Session;
HttpContext.Current.Session["test"] = "test";
HttpContext.Current.Response.Write(ss.SessionID);
return "ok";

}

------------
public class MyServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();

HttpSession session = request.getSession(true);

out.println("The session ID: " + session.getId() + "<BR>");

i may need that session id.
how can i get that session id from servlet ?
It will be in the response somewhere - it's a case of finding it. As I
said before, check URLs and cookies.

Jon
Jun 27 '08 #8
OK. I 'll try. Thanks for your helping me.
>It will be in the response somewhere - it's a case of finding it. As I
said before, check URLs and cookies.

Jon
Jun 27 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Chris Morgan | last post: by
2 posts views Thread by Patrick | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.