Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Anybody give me alternative of this code in c#. I used to server to server communication but got error in belove code. I unable to convert the below Java code to c#

java.net.HttpURLConnection httpurlconnection = null;
httpurlconnection.setDoOutput(true);


Regards
Ravi
Posted
Updated 19-May-11 23:47pm
v3

 
Share this answer
 
That code will throw a NullReferenceException in Java on the second line anyway.

Edit: from your comment below it looks like you want to use WebRequest/HttpWebRequest. Have a look at this MSDN page[^] which should help you.
 
Share this answer
 
v2
The code which you have mentioned in the Second line will throws an Exception.
 
Share this answer
 
what the code do...please explain

java.net.HttpURLConnection httpurlconnection = null;
httpurlconnection.setDoOutput(true); specially this line
 
Share this answer
 
Comments
Ravi Sharma 2 20-May-11 6:16am    
Its do server to server communication ......
ishare my whole code..


String

tpslIp =





StringdirectRefUrl = http://10.12.119.74:80/PaymentGateway/test.aspx;
java.net.



URL url = new java.net.URL(tpslIp);
HttpURLConnection httpurlconnection = null; /* I cannot got conversion of this code*/

httpurlconnection = (java.net.

httpurlconnection.setDoOutput(

true);
httpurlconnection.setDoInput(

true);
httpurlconnection.setUseCaches(

true);
httpurlconnection.setRequestMethod(

"POST");
httpurlconnection.setRequestProperty(

"Referer", directRefUrl);
java.io.

ObjectOutputStream objectoutputstream1 = new java.io.ObjectOutputStream(httpurlconnection.getOutputStream());

Please give me proper answer.
BobJanova 20-May-11 6:23am    
See my updated answer.
senguptaamlan 20-May-11 6:25am    
try the following code


string responseString = string.Empty;
WebRequest request = WebRequest.Create(@"http://10.12.119.74:80/PaymentGateway/test.aspx");
request.Credentials = System.Net.CredentialCache.DefaultCredentials;
//create a proxy if you are behind a poxy server
WebProxy proxy = new WebProxy();
proxy.Credentials = CredentialCache.DefaultCredentials;
proxy.Address = new Uri(@"http://proxyaddres");
request.Proxy = proxy;
using (System.IO.StreamReader reader = new System.IO.StreamReader(request.GetResponse().GetResponseStream()))
{
responseString = reader.ReadToEnd();
}
Console.WriteLine(responseString);
Console.ReadLine();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900