HTTP request og svar
Jeg har flg kode i java, og skal lave det i en .NET (C#) version.Er endnu ikke helt stiv i .NET net-klasser.
Håber nogen kan give en ide el. eksempel.
private String logon() {
try {
String user = "UserId";
String password = "Password";
String adresse = ServicesUrl + "/xxx/yyyy/zzzzz";
// Først laves signon
String logonrequest =
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"yes\"?>"
+ "<root xmlns=\"http://www.xxxx.dk\">"
+ "<Gctp v=1>"
+ "<Sik function=\"signon\" userid=\""
+ user
+ "\""
+ " password="
+ "\""
+ password
+ "\""
+ "/>"
+ "</Gctp>"
+ "</root>";
System.out.println("Logonrequest : " + logonrequest);
URL url = new URL(adresse);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setDoOutput(true);
con.setRequestProperty("user-agent", "XXX/1.0");
// Send requestet
sendRequest(con, logonrequest);
// Modtag svar
InputStream in = con.getInputStream();
//lav et Document
// laver en masse med in
// ...
String tokenString = con.getHeaderField("Set-Cookie");
return tokenString;
} catch (Exception e) {
//...
}
}
private void sendRequest(HttpURLConnection con, String request) {
try {
OutputStream out = con.getOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(out);
byte[] bytes = request.getBytes();
bos.write(bytes, 0, bytes.length);
bos.flush();
} catch (Exception e) {
}
}
private String logon() {
try {
String user = "UserId";
String password = "Password";
String adresse = ServicesUrl + "/xxx/yyyy/zzzzz";
// Først laves signon
String logonrequest =
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"yes\"?>"
+ "<root xmlns=\"http://www.xxxx.dk\">"
+ "<Gctp v=1>"
+ "<Sik function=\"signon\" userid=\""
+ user
+ "\""
+ " password="
+ "\""
+ password
+ "\""
+ "/>"
+ "</Gctp>"
+ "</root>";
System.out.println("Logonrequest : " + logonrequest);
URL url = new URL(adresse);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setDoOutput(true);
con.setRequestProperty("user-agent", "XXX/1.0");
// Send requestet
sendRequest(con, logonrequest);
// Modtag svar
InputStream in = con.getInputStream();
//lav et Document
// laver en masse med in
// ...
String tokenString = con.getHeaderField("Set-Cookie");
return tokenString;
} catch (Exception e) {
//...
}
}
private void sendRequest(HttpURLConnection con, String request) {
try {
OutputStream out = con.getOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(out);
byte[] bytes = request.getBytes();
bos.write(bytes, 0, bytes.length);
bos.flush();
} catch (Exception e) {
}
}