HighTechTalks DotNet Forums  

Socket hang problem

Dotnet VJSharp microsoft.public.dotnet.vjsharp


Discuss Socket hang problem in the Dotnet VJSharp forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Tejaswi
 
Posts: n/a

Default Socket hang problem - 10-26-2004 , 06:09 PM






Hello!
I have a J# socket client that does an HTTP Post. Code pasted below. This
client works fine on my XP and Win 2003 boxes, but on my Win 2000 Server box,
the socket just hangs when it tries to read. No exception nothing just hangs.
Any suggestion?

public static String httpPost(String url, String payload, String
ContentType)throws Exception, System.Exception
{
WebResponse result = null;
StreamReader sr = null;

try
{
WebRequest req = WebRequest.Create(url);
req.set_Method("POST");
//req.set_ContentType("application/x-www-form-urlencoded");
req.set_ContentType(ContentType);

ubyte[] SomeBytes = null;

if (payload != null)
{

//SomeBytes = HttpUtility.UrlEncodeToBytes(payload);
SomeBytes = Encoding.get_UTF8().GetBytes(payload);
req.set_ContentLength(SomeBytes.length);
Stream newStream = req.GetRequestStream();
newStream.Write(SomeBytes, 0, SomeBytes.length);

newStream.Close();
}
else
{
req.set_ContentLength(0);
}

result = req.GetResponse();
Stream ReceiveStream = result.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
sr = new StreamReader(ReceiveStream, encode);


System.Text.StringBuilder strb = new StringBuilder();
String str;
while ((str = sr.ReadLine()) != null)
{
strb.Append(str).Append( "\r\n");
}


return System.Web.HttpUtility.UrlDecode(strb.ToString(), encode);
}
catch(Exception e)
{
throw e;
}
catch (System.Exception se)
{
throw se;
}
finally
{
if(sr != null)
sr.Close();

if (result != null)
result.Close();
}
}//getPage



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.