Regarding .Net Application communication with Servlet

A

Arti

Hi,

I have a .Net application which has to communicate to Servlet on TomCat
Server. I am able to send the request but it throws an exception while
retrieving the response(Exception:The underlying connection was closed:
An unexpected error occurred on
a receive.)

Here is the code snippet .

-------------------------------------------------------------------------------------------------------
string uri =
"http://192.168.42.79:8080/MYLOGINPAGE/AMCWEBLOGINGATEWAY?LOGINID=abc&...";
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(uri);

request.CookieContainer = new CookieContainer()
;
request.KeepAlive = false;
request.ProtocolVersion=HttpVersion.Version10;
request.Credentials =
CredentialCache.DefaultCredentials;

HttpWebResponse response = (HttpWebResponse)
request.GetResponse();
---------------------------------------------------------------------------------------------------------------

Any comments of URL help is appreciated. Thank you.

Regards,
Art
 
J

Joerg Jooss

Thus wrote arti,
Hi,

I have a .Net application which has to communicate to Servlet on
TomCat
Server. I am able to send the request but it throws an exception while
retrieving the response(Exception:The underlying connection was
closed:
An unexpected error occurred on
a receive.)
Here is the code snippet .

Can you hook up a proxy like Fiddler to see the HTTP messages?

Cheers,
 
A

Arti

Thanks a lot for your reply.
I am getting the following message in the fiddler:

X-HTTPPROTOCOL-VIOLATION: [HTTP Protocol Violation] HTTP/1xx responses
MUST NOT contain a body, but a non-zero content-length was
returned.[HTTP Protocol Violation] The Server did not return properly
formatted HTTP Headers. Maybe missing altogether (e.g. HTTP/0.9), maybe
only \r\r instead of \r\n\r\n?

Do We need to set the header in the response explicitly?

Here is servlet code:
-------------------------------------------------------------------------------------------------------------
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
System.out.println("START VALIDATION");
loginId = "" + req.getParameter("LOGINID");
passward = "" + req.getParameter("PASSWD");
if(loginId == null || loginId.length() <= 0 || passward == null
|| passward.length() <= 0 )
{
System.out.println("Invalid imput user name and
passward.");
res.sendError(400, "Invalid imput user name and
passward.");
} else
{
System.out.println("login ID : " + loginId);
System.out.println("Passward : " + passward);
res.setHeader("HI", loginId);
res.setStatus(100);
out = res.getWriter();out.write("LOGIN DONE");
}
System.out.println("Failed to validate user");
}
--------------------------------------------------------------------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top