Recently I needed to move some code from Java to C#.
This is one of the methods that I couldn't rewrite... can someone help me?
public static String coreApiPostRequest(URL url, String input) {
try {
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/xml");
String responseMessage=null;
OutputStream os = conn.getOutputStream();
os.write(input.getBytes());
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
os.flush();
if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));
String output;
while ((output = br.readLine()) != null) {
System.out.println(output);
responseMessage = output;
}
conn.disconnect();
return responseMessage;
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}