473,605 Members | 2,690 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6063
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.Cre ate(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.UserAge nt = "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.KeepAli ve = true;
request.Content Type = "applicatio n/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.Protoco lVersion = HttpVersion.Ver sion11;
request.Content Length = postData.Length ;
request.AllowAu toRedirect = true;

using (Stream writeStream = request.GetRequ estStream())
{
Encoding encoding = Encoding.GetEnc oding("ISO-8859-9");
byte[] bytes = encoding.GetByt es(postData);
writeStream.Wri te(bytes, 0, bytes.Length);
}
using (HttpWebRespons e response =
(HttpWebRespons e)request.GetRe sponse())
{
using (Stream responseStream = response.GetRes ponseStream())
{
using (StreamReader readStream = new
StreamReader(re sponseStream, Encoding.GetEnc oding("ISO-8859-9")))
{
result = readStream.Read ToEnd();
}
}
}

On Wed, 14 May 2008 04:56:03 -0700 (PDT), "Jon Skeet [C# MVP]"
<sk***@pobox.co mwrote:
>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() {
HttpSessionStat e ss = HttpContext.Cur rent.Session;
HttpContext.Cur rent.Session["test"] = "test";
HttpContext.Cur rent.Response.W rite(ss.Session ID);
return "ok";
}
------------
public class MyServlet extends HttpServlet {

public void doGet(HttpServl etRequest request, HttpServletResp onse
response)
throws ServletExceptio n, IOException
{
response.setCon tentType("text/html");
PrintWriter out = response.getWri ter();

HttpSession session = request.getSess ion(true);

out.println("Th e 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.co mwrote:
>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() {
HttpSessionStat e ss = HttpContext.Cur rent.Session;
HttpContext.Cur rent.Session["test"] = "test";
HttpContext.Cur rent.Response.W rite(ss.Session ID);
return "ok";

}

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

public void doGet(HttpServl etRequest request, HttpServletResp onse
response)
throws ServletExceptio n, IOException
{
response.setCon tentType("text/html");
PrintWriter out = response.getWri ter();

HttpSession session = request.getSess ion(true);

out.println("Th e 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3466
by: Chris Morgan | last post by:
I'm trying to get php to run on my webserver as a Java Servlet, it works the first time but fails the second time and crashes the JVM with the following error: I have tried the latest versions of PHP 4. (release and dev) I would appreciate any help with this issue. -- Chris
2
3942
by: Patrick | last post by:
I'm using Jakarta-POI to create a huge Excel spreadsheet. I get the error below when the spreadsheet grows to a large size. It seems to have something to do with the number of "cell" objects that I create. If I destroy other objects that I don't need any more, then I can create more "cell" objects. Unfortunately, I cannot destroy any more of my other objects without breaking the program. This does not appear to be a problem that is...
11
9233
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in C++. I find my self sometimes, trying Object app = Object(); Object *app = Object(); Object app = new Object();
5
3843
by: Ike | last post by:
Through Java, I am attempting to connect to a MySQL 4.12 server on a remote computer. I can connect fine via php. I cann connect fine via Java, through a servlet, when the servlet is on the same machine (localhost) as the MySQL DB. However, when they are on different machines with different IPs, calling across the Internet (and there are no firewall issues -- I can connect fine to the remote MySQL DB via php from the same machine, not...
0
2588
by: ErikaW | last post by:
Hi all, I've tried to google this but could not find a clear solution. I have a Web application developed in JDevloper using mostly html and Javascript. I have a pre-defined PDF form which I merge with a XML file. I want to be able to save the form automatically for the User so as to prevent typing errors i.e. c:/erikaTemp/subFolder/erika_12345.pdf but from what I've seen this can only be done via the the 'File download' pop up which only...
8
28511
by: ajos | last post by:
hi frnds, im trying to convert my servlets database configuration from ms access to mysql database.however im getting some error like no driver found exception. to verify this error ive made a simple database in jsp(just to check if my mysql is working smoothly otherwise) which access' the username.....but in the process im getting a error--> java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO) i have...
3
2906
by: arasub | last post by:
ep 20, 2007 11:25:57 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.5.0_12\bin;.;C:\WINDOWS\System32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\j2sdk_nb\j2sdk1.4.2\bin;C:\Program...
1
3359
by: hkma08 | last post by:
I dont know I should post JSP error in here or not. If not please redirect me to another one. Thx. I just installed apache tomcat with mysql with java, but i got error when try to connect to mysql database, what is happening? Here is my error msg: org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 3 in the jsp file: /tutorial/test.jsp Syntax error on tokens, delete these tokens 1: <%@ page...
2
1985
by: hkma08 | last post by:
I dont know I should post JSP error in here or not. If not please redirect me to another one. Thx. I just installed apache tomcat with mysql with java, but i got error when try to connect to mysql database, what is happening? Here is my error msg: org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 3 in the jsp file: /tutorial/test.jsp Syntax error on tokens, delete these tokens <%@ page...
0
7934
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8424
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8286
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6742
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5886
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5445
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3958
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2438
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1537
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.