これは残りのクライアントのJavaコードです。作成に問題があります。このクライアントで同等の C# を作成するにはどうすればよいですか? いくつかの例が必要です
public class RestServiceClient {
public static final String BASE_URL = "http://localhost:9080/PPAUploadDocRestService/rest/uploadDocument";
public static void main(String[] args) {
addDocument();
}
public static void addDocument() {
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(BASE_URL);
MultipartEntity reqEntity = new MultipartEntity();
FileBody fileBody = new FileBody(new File("C:/projects/Db2PpaPpacardsppastages.xsd"));
reqEntity.addPart("file", fileBody);
reqEntity.addPart("fileName", new StringBody("Db2PpaPpacardsppastages.xsd"));
reqEntity.addPart("processId", new StringBody("2872"));
reqEntity.addPart("document", new StringBody(generateDocument()));
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
System.out.println(response.getStatusLine().getReasonPhrase());
} catch(Exception e) {
e.printStackTrace();
}
}
private static String generateDocument() {
JSONObject object = new JSONObject();
object.put("docNum", "NickDoc");
object.put("docDate", "" + new Date().getTime());
object.put("docTypeId", "49");
object.put("questionId", "1728");
object.put("description", "test by NIvanov REST");
object.put("resolution", "");
object.put("workGroupMembers", "");
object.put("inDocNum", "inNickDoc");
object.put("inDocDate", "" + new Date().getTime());
object.put("outDocNum", "outNickDoc");
object.put("outDocDate", "" + new Date().getTime());
object.put("docName", "NickDocName");
object.put("employeeId", "1");
object.put("cardId", "647");
object.put("bpmDocId", "");
object.put("docCode", "TNT");
return object.toString();
}
}
HttpWebRequest
andHttpWebResponse
オブジェクトの使用を検討しています。それは本当です?