Java to Asp .Net
Dear Friends
Any body can help in converting this piece of code from Java to Asp. Net.
public createURL(... {
. . .
this.metodo = "http";
this.host = "<application>.<customer>.azormarket.com";
this.puerto = 8086;
this.trx = "/xml/FullAvail1_0.do";
try{
this.url = new URL(metodo, host, Integer.parseInt(puerto), trx);
}
catch (MalformedURLException e)
{ . . . }
}
public String sendAndReceive(String xmlReq) throws . . .
{ HttpURLConnection uc=null;
// Codificación en Base64
String userPwd = "<user>" + ":" + "<password>";
String userPassword = Base64Converter.encode(userPwd.getBytes());
// Parametro HTTP llamado xml
xmlReq = "xml=" + xmlReq;
try {
uc = (HttpURLConnection) url.openConnection();
Permission per = uc.getPermission();
uc.setRequestProperty("Authorization", "Basic " + userPassword);
uc.setRequestMethod("POST");
uc.setRequestProperty("Content-length",
String.valueOf(xmlReq.getBytes().length));
uc.setDoInput(true);
uc.setDoOutput(true);
//Write POST
OutputStream out = uc.getOutputStream();
out.write(xmlReq.getBytes());
out.flush();
//Read Response
String line;
StringBuffer xmlResponse = new StringBuffer();
InputStream content = (InputStream) uc.getInputStream();
BufferedReader in;
in = new BufferedReader(new InputStreamReader(content));
while((line = in.readLine()) != null) {
xmlResponse.append(line); }
} finally {
try { in.close(); } catch(Exception e){};
try { out.close(); } catch(Exception e){};
try { uc.disconnect(); }
catch(Exception e){}; }
catch (FileNotFoundException fnfe) { . . . } catch (Exception e){ . . .
} return xmlResponse.toString();
}</html>
|