這裏是休息客戶端的java代碼。我在創建時遇到問題。 如何在此客戶端上創建C#等價物?我需要一些例子其餘客戶端的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
和HttpWebResponse
對象。這是真的?