hi im trying to convert java to c# now. trying to understand how to change this to C#.

first problem that i have met.

in java, httpConnection has the setRequestProperty and get HeaderField. however i cant find the equivalent for these in c# for cookie.

conn.setRequestProperty("cookie", mSession);

String cookie = conn.getHeaderField("Set-cookie");

second problem that i have met. i have changed the getResponseCode() to getResonse() in C#. but i got an error Cannot implicitly convert type 'System.Net.WebResponse' to 'int'. also i am trying to convert HttpConnection.HTTP_OK, dataInputStream and OpenInputStream to c#, which i could nto find an equivalent.

int rc=0; //conn.getResponseCode();

}catch(Exception e)

System.out.println("rc have already"+conn.getResponseCode());
if(rc==HttpConnection.HTTP_OK) {
StringBuffer text=new StringBuffer();

DataInputStream din=new DataInputStream(conn.openInputStream());

int n=din.readInt();
while(n-->0) {
text.append(' ');

Re: Smart Devices VB and C# Projects httpwebrequest

Alex Yakhnin MSFT

I don't think it's a good idea to convert from one language to another line by line. The better approach would be to figure out (functional specs) what the old program is doing and implement in other language. For example, you know that your Java program connects to a web server and retreives the data from it, so you should be able to find a code sample that does that in .NET and adapt it to your requirements.

To answer your "Cookies" question, take a look at this old post of mine:


Re: Smart Devices VB and C# Projects httpwebrequest


i changed the rc = getResponseCode() to rc = getResponse, but got this error..

Error 1 Cannot implicitly convert type 'System.Net.WebResponse' to 'int'

in java HttpConnection.HTTP_OK means request has succeeded. but i need to convert it to c#. what is the equivalent

Re: Smart Devices VB and C# Projects httpwebrequest

Alex Yakhnin MSFT

Once again take a look at the samples of working with HttpWebRequest/HttpWebResponse classes available on the internet. For example this one:


To answer your question about the status, the HttpWebResponse has the Status property that you can use.