Answer the question
In order to leave comments, you need to log in
How to make a get request in Java?
Help me translate from C# to Java or what should I learn to write such code in Java?
private string GET(string sUrl, string Data)
{
string Out = "";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sUrl + "?" + Data);
//req.Timeout = -1;
//MessageBox.Show("1");
req.KeepAlive = false;
//req.KeepAlive = true;
//req.ServicePoint.Expect100Continue = false;
// req.Credentials = CredentialCache.DefaultCredentials;//
StreamReader sr = null;
try
{
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream stream = resp.GetResponseStream();
sr = new StreamReader(stream, Encoding.Default);
//textBox1.Text += String.Format("{0}\n", sr);
Out = sr.ReadToEnd();
MessageBox.Show(Out);
sr.Close();
}
catch(Exception ex) {
MessageBox.Show("error" + " " + ex.Message);
}
finally
{
if (sr != null)
sr.Close();
}
return Out;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question